Hi all,
Is there any way to find out a total Courtyard area (total for all the components on the PCB)?
Many thanks
Hi all,
Is there any way to find out a total Courtyard area (total for all the components on the PCB)?
Many thanks
Interesting idea for real estate estimate purposes. Is that your use case?
If there was a way to get a single courtyard area, then getting the total would be a very simple python script. But I donāt know if there is one.
Iām still using v7 (and donāt intend to upgrade).
In v7, I do this to get Area:
For object of interest:
⢠On a Copper-Layer of your choice, Draw a Polygon-Shape to match the desired outline
⢠Select the Shape you just created
⢠Right-Click it and Create a Zone from it
⢠Select the Zone, Right-Click, Fill Selected
The Area will display at bottom of PCB Panelā¦
Multiple Zone Areas are not Additive so must do individually (and get out your calculatorā¦)
ADDED: you can use other Layers to do it but, not all of them⦠User Layer worksā¦
@Heath_Raftery - thatās exactly my use case. Big board with lots of components went through a major updates. Just out of curiosity wanted to find out total Courtyard info before and after.
@BlackCoffee - this is the selected zone area. I use it already, but for different use case. What I asked for is a total Courtyard area - all components Courtyard areas added together. They are scattered around the board and with gaps in between them, so drawing a zone wonāt work.
Yes, I know what you asked for and I answered āthey are not additive⦠get out your calculatorā
Itās over 1200 total components, (around 25 different footprint used multiple times).
Iāll think about a script rather than do it manually on a calculator, but thanks for your advise anyway.
I had a quick squizz and noticed you can query a footprint for itās ābounding hullā and its ācached courtyardā which sound encouraging.
Further, once you have a SHAPE_POLY_SET, finding its area looks very straight forward too:
So given that courtyards are by definition not overlapping, on the surface this seems eminently doable.
Well that was shockingly simple:
import pcbnew
pcb = pcbnew.GetBoard()
area = 0.0
for fp in pcb.GetFootprints():
cy = fp.GetCachedCourtyard(pcbnew.F_CrtYd)
area = area + cy.Area()
area / (pcbnew.PCB_IU_PER_MM*pcbnew.PCB_IU_PER_MM)
Type that into the pcbnew console and away you go?
I do know there is documentation on: https://docs.kicad.org/ but now I see for the first time there is documentation about python scripting hidden on that same docs.kicad.org site.
There is a small section about scripting in the PCB manual: https://docs.kicad.org/9.0/en/pcbnew/pcbnew.html#scripting but that also does not mention the doxygen stuff.
Yes, Iāve learnt to keep a link handy. Itās very hard to discover, despite being irreplaceable documentation.
It returns 0.0, but it a good start. Iāll experiment with this later when have a moment. Thanks!
I created a bug report for it:
I ran it on a completed board, that only has components on the front. The number seemed plausible to me (3822mm2 on a lightly packed 100x100 board).
I wonder if a ācached courtyardā needs to be triggered by something.
Anyway, Iāll let you have a play. It will be interesting what you discover.
It is a Good start. And, after deleting Cached from Courtyard, it works (though, I did Not compare to actual Areas⦠just wanted to check āCachedā issueā¦
import pcbnew
pcb = pcbnew.GetBoard()
area = 0.0
for fp in pcb.GetFootprints():
cy = fp.GetCourtyard(pcbnew.F_CrtYd)
area = area + cy.Area()
Hereās the Result:
area / (pcbnew.PCB_IU_PER_MM*pcbnew.PCB_IU_PER_MM)
1494.524441916688
I tried it on a few my projects as well as downloaded from GitHub. No luck. Always returns 0.0.
However I created a new project with two random parts and it gives the result as it should.
Perhaps itās something to do with older / newer KiCad version used for the project they donāt work. I donāt know, but will investigate.
The script works fine! Many thanks again @Heath_Raftery !
EDIT: Actually itās very random. I closed and re-open the new project I just made and now also shows 0.0. Will investigate.
I canāt say because I still use v7.
However, for morning Fun while drinking black coffeeā¦
I added Courtyard-Area calc to my Selected-Trackās-Area Plugin.
Tested with Two Courtyards at 25x25mm. I left it such that User needs to select desired Tracks and Courtyards are on Front
Plugin attached - old style so, just put it into the proper folder on your system and Edit the .PNG name to your desired Icon.
my_Area_Calc.py (1.5 KB)
Many thanks for this.
Tried it on a few different projects and it reposrts tracks OK, but no Courtyards.
Tried selecting them with F.Cu or F.Courtyard layer active. No luck:
It there something wrong with my system (Xubuntu + KiCad 9.0.5)?
What do I do wrong?
Iāll check it on another machine (Win11 + KiCad 9.0.4) after the weekend and let you know.
I placed a bunch of footprints and all of their courtyards got added⦠Iām on a Mac.
Perhaps other users can chime-in and help you with Linux and perhaps Windows will work out okā¦
The code I posted does Not use āSelectedā Courtyard but, perhaps you can add āSelectedā to the code and report backā¦
A few years ago, I tried to do something similar with the aim of estimating the available PCB area for a given design.
How strange!
I started to write down some debugging ideas, but quickly discovered I can reproduce your result!
I have the same project open in a Mac Studio running Sequoia 15.6.1, KiCad 9.0.4, and on a MacBook Air running Sequoia 15.6, KiCad 9.0.4. On the MacBook all is well, on the Mac all the Areas are zero!!
Something fishy going on hereā¦