如何使用 KiCAD pcbnew 插件 Python API 获取封装参考设计ator 列表

当你在 KiCAD 的 Python API 中有 FOOTPRINT 对象或封装列表时(例如来自 board.GetFootprints()),你可以使用以下命令获取它们的参考设计ators 如 C11R4

footprint_get_reference.py
footprint.GetReference()

完整插件示例:

kicad_footprint_plugin.py
#!/usr/bin/env python
import pcbnew
import os

class SimplePlugin(pcbnew.ActionPlugin):
    def defaults(self):
        self.name = "Pcbnew 中显示的插件名称:Tools->External Plugins"
        self.category = "描述性类别名称"
        self.description = "插件及其功能的描述"
        self.show_toolbar_button = False # 可选,默认为 False
        self.icon_file_name = os.path.join(os.path.dirname(__file__), 'simple_plugin.png') # 可选,默认为 ""

    def Run(self):
        board: pcbnew.BOARD = pcbnew.GetBoard()
        footprints: list[pcbnew.FOOTPRINT] = board.GetFootprints()

        # TODO 用 [board] 做些有用的事
        for footprint in footprints:
            print(footprint.GetReference())

SimplePlugin().register() # 实例化并注册到 Pcbnew

Check out similar posts by category: Electronics, KiCad