Wie man das Board-Objekt mit der KiCAD-pcbnew-Plugin-Python-API erhält
English
Deutsch
Bei der Verwendung von KiCADs Python-API für pcbnew können Sie einfach ein Board-Objekt mit pcbnew.GetBoard() erhalten:
get_board_example.py
board: pcbnew.BOARD = pcbnew.GetBoard()Das : pcbnew.BOARD ist optional, aber es wird Ihrem Editor (wie Visual Studio Code) mitteilen, welches Objekt zu erwarten ist, für eine bessere Autovervollständigung.
Vollständiges Plugin-Beispiel:
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 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