Como obter objeto board usando a API Python do plugin KiCAD pcbnew

Ao usar a API Python do KiCAD para pcbnew, você pode simplesmente obter um objeto board usando pcbnew.GetBoard():

get_board_example.py
board: pcbnew.BOARD = pcbnew.GetBoard()

O : pcbnew.BOARD é opcional mas dirá ao seu editor (como visual studio code) qual objeto esperar para melhor autocompletar.

Exemplo completo de plugin:

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

class SimplePlugin(pcbnew.ActionPlugin):
    def defaults(self):
        self.name = "Plugin Name as shown in Pcbnew: Tools->External Plugins"
        self.category = "A descriptive category name"
        self.description = "A description of the plugin and what it does"
        self.show_toolbar_button = False # Optional, defaults to False
        self.icon_file_name = os.path.join(os.path.dirname(__file__), 'simple_plugin.png') # Optional, defaults to ""

    def Run(self):
        board: pcbnew.BOARD = pcbnew.GetBoard()
        # TODO Do something useful with [board]
        print(board)

SimplePlugin().register() # Instantiate and register to Pcbnew

Check out similar posts by category: Electronics KiCAD