简体   繁体   中英

Placing a component using KiCad's Python API

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.

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")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM