I’ve dug through some older (and somewhat recent) posts, but cannot seem to find a working answer for this. I am using Kicad 6.0.8 on Windows 11.
Using Python, I would like to make an array of zones and assign them a net name. (For an array of LEDs). I have no problem creating the zones, however I cannot seem to assign net names to the zones. I tried the following from another post:
net = pcbnew.NETINFO_ITEM(board, "net_TEST2")
z = pcbnew.ZONE(board)
… but I get the error AttributeError: 'BOARD' object has no attribute 'AppendNet'
So, two questions:
Is there a way to create and assign net names via Python in 6.x? I know I can pass z.SetNetCode(<INTEGER OF NAME ALREADY IN LIST>)
In the big picture, what is the best solution to this problem? Assume I already have a schematic that has the LED array with net names that I want to apply to the zones.
Basically, I want to auto-layout the zone locations and LED footprint arrays. Bonus points for being able to dynamically adjust the number of LEDs in the schematic and layout.
AppendNet() is a method of NETINFO_LIST, not BOARD. Try
But if you have a schematic then you shouldn’t have to create any nets, only use existing ones, for that use board.GetNetsByName() to get net map.
There is no scripting in schematic editor yet. But in general if you have lots of repeated pieces then create a hierarchical sheet, put the repeated piece in it and replicate the sheet required times in schematic. Then you can use place footprints/replicate layout plugins to do initial placing in an array and then copy surrounding stuff like tracks, zones (I think) current limiting resistors if you have them etc.
ADDED: Amusing myself…
Video shows Double-Clicking Zones and showing the Net they belong to.
The Middle Zone is not assigned to a Net and shows no Net in panel.
Regarding Array: You can select a Zone containing LED’s and Create an Array with it (Right-Click>Special_Tools>Create_Array. Works !) Image shows LED’s with Vcc net on Top layer and GND on Bottom layer…
Thank you for the feedback. In my case there are no tracks on the PCB at all. It is a single sided board with SMT LEDs. I did find the net-index to net-name table in the .kicad_pcb file. I am already using hierarchical sheets, but due to the nature of the design, I need to adjust the zone layouts intra-sheet to avoid creating a ton of sheets. Because of this, I would rather create the array in python rather than use the Replicate Layout plugin.
@qu1ckboard.GetNetsByName() is what I was looking for. Is there an example of its usage somewhere? What I tried did not work. As a fallback, I can pull the net index and name data in by parsing the net table in pcb file manually in python, but GetNetsByName() should do this for me I believe.
I assume you want to give each LED a little heatsink, If the LED pattern is regular, then you can very simple create a custom footprint for the LED with big pads. This can be done in several way. You can place a pad, then press [Ctrl + E] to enter “pad edit mode” and then you can add graphics such as filled rectangles lines and arcs to a pad.
Another way is to use several pads with the same pad number in the footprint and then overlap them partially. Note that you can disable paste and/or solder mask layers for each pad and this makes it easy to combine them into something fancy.