简体   繁体   English

使用 KiCad 的 Python API 放置组件

[英]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.我对 KiCad 的 python API (5.1) 有问题,我找不到在 PCB 上添加组件的方法。

I found some examples but they no longer work with the version of KiCad I am using.我找到了一些示例,但它们不再适用于我正在使用的 KiCad 版本。 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.下一步是通过 C++ 代码了解如何将组件放置在板上,但在此之前,我认为值得在这里寻求帮助。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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