Electronics > KiCad
KiCad scripting - assigning refs to components while respecting spatial layout
kmm:
For some context I'm a Python guy (day job is mostly Python-based IT automation glue) but I'm not really sure where to start with scripting KiCad. The docs are (generously) not particularly great, the API is not particularly "pythonic", and as far as I can tell docs haven't been updated for the 8.x version I'm using.
I have this LED matrix and all I want to do with it is iterate through all the LED footprints from top to bottom as on the drawing and assign a sequential ref (D1 .. D576) to each LED (row one would be D1 .. D24, row 2 would be D25 .. D48, and so on). Reasoning is just that it's much easier to lay out the LEDs as untagged footprints and then sync them to the schematic after the fact, since as far as I can tell there's no way to tell Pcbnew to lay out components with a geometry or regular spacing. Shuffling around footprints imported from the schematic with the mouse 576 times sounds like pain.
Really all I'm looking for is a link to an example of this sort of use case, if anyone has one handy.
abeyer:
A few things:
1. The python bindings are SWIG generated, and in my experience they are about as usable as any autogenerated ones will get (which as you point out is not great) without a lot of documentation work. Failing that you're assumed to be familiar or willing to get familiar with the underlying code SWIG is wrapping.
2. The python bindings, last I heard, aren't intended to be the future and may not be getting much love. There's a new IPC based interface that I think is available in recent versions, though I haven't tried it myself.
3. KiCad files are lispy text content, and easy to parse and manipulate as such. If you don't absolutely need live interaction in the application interface itself, an external script that transforms your schematic/pcb file in place and the reloading in into KiCad tends to be a faster approach to this kind of this in my experience.
MitjaN:
Take a look at PlaceFootprints action plugin (https://github.com/MitjaNemec/PlaceFootprints). It might even be what you need. Otherwise you can at least look at the code for ideas
ksjh:
I have not used KiCad Python scripting that often, but I found that KiCad has a built-in function to re-annotate footprints in the PCB editor: Geographical Reannotate... in the Tools menu. Would that work for your purpose?
kmm:
--- Quote from: ksjh on November 10, 2024, 08:17:07 am ---I have not used KiCad Python scripting that often, but I found that KiCad has a built-in function to re-annotate footprints in the PCB editor: Geographical Reannotate... in the Tools menu. Would that work for your purpose?
--- End quote ---
I believe this is exactly what I need, thanks!
Navigation
[0] Message Index
[#] Next page
Go to full version