如何使用 KiCAD pcbnew 插件 Python API 获取板对象
使用 KiCAD 的 pcbnew Python API 时,你可以简单地使用 pcbnew.GetBoard() 获取板对象:
get_board_example.py
board: pcbnew.BOARD = pcbnew.GetBoard(): pcbnew.BOARD 是可选的,但会告诉你的编辑器(如 visual studio code)期望哪个对象以获得更好的自动补全。
完整插件示例:
kicad_simple_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()
# TODO 用 [board] 做些有用的事
print(board)
SimplePlugin().register() # 实例化并注册到 PcbnewCheck out similar posts by category:
Electronics, KiCad
If this post helped you, please consider buying me a coffee or donating via PayPal to support research & publishing of new posts on TechOverflow