Reputation: 41
I have a problem with KiCad's python API (5.1), I cannot find a way to add a component onto the PCB.
I found some examples but they no longer work with the version of KiCad I am using. The next step is going through the C++ code to understand how a component is placed on the board, but before that, I thought was worth asking for help here.
Upvotes: 2
Views: 624
Reputation: 41
Adding a component is quite easy, just instantiate a module and place it on the board.
m = pcbnew.FootprintLoad("D:/path/to/lib.pretty","footprint_name")
board.Add(m)
But be aware that you cannot add the same module multiple times, you have to create multiple modules. I found this out with hours of debugging.
footprint = pcbnew.FootprintLoad("/usr/share/kicad/modules/MountingHole.pretty", "MountingHole_3.2mm_M3")
board.Add(pcbnew.MODULE(footprint))
board.Add(pcbnew.MODULE(footprint))
board.Save("board.kicad_pcb")
Upvotes: 2