Wie man eine Liste aller Footprints mit der KiCAD-pcbnew-Plugin-Python-API erhält
English
Deutsch
Bei der Verwendung von KiCADs Python-API für pcbnew können Sie eine Liste von FOOTPRINT-Objekten mit
get_footprints.py
board: pcbnew.BOARD = pcbnew.GetBoard()
footprints: list[pcbnew.FOOTPRINT] = board.GetFootprints()erhalten. Das : pcbnew.BOARD und : list[pcbnew.FOOTPRINT] sind optional, aber sie werden Ihrem Editor (wie Visual Studio Code) mitteilen, welches Objekt zu erwarten ist, für eine bessere Autovervollständigung.
Vollständiges Plugin-Beispiel:
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()
footprints: list[pcbnew.FOOTPRINT] = board.GetFootprints()
# TODO Do something useful with [board]
for footprint in footprints:
print(footprint)
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