KiCAD pcbnew プラグイン Python API を使用してボードオブジェクトを取得する方法

pcbnew 用の KiCAD 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() # インスタンス化して Pcbnew に登録

同じカテゴリの類似記事をチェック: エレクトロニクス KiCad