Jak získat všechny vybrané objekty pomocí Python API KiCAD pcbnew pluginu

Když máte FOOTPRINT objekt nebo seznam footprintů v Python API KiCAD jako z board.GetFootprints(), můžete získat jejich referenční označení jako C11 nebo R4 pomocí

get_current_selection.py
pcbnew.GetCurrentSelection():

Všimněte si, že nejen footprinty mohou být vybrané ale také jiné objekty jako tvary, viy, pady atd.

Kompletní plugin příklad:

kicad_get_current_selection_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()

        for selected_object in pcbnew.GetCurrentSelection():
            # TODO Udělat něco užitečného s selected_object
            print(selected_object)

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

Příklad výstup (excerpt):

output.txt
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8b70> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8de0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8c30> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8b40> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8db0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8c00> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8ba0> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8e10> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8bd0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8b70> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8de0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8c30> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8b40> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8db0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8c00> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8ba0> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8e10> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8bd0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8b70> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8de0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8c30> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8b40> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8db0> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8c00> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8ba0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8e10> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8bd0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8b70> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8de0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8c30> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8b40> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8db0> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8c00> >
<pcbnew.PCB_TRACK; proxy of <Swig Object of type 'PCB_TRACK *' at 0x7fc49d2a8ba0> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8e10> >
<pcbnew.FOOTPRINT; proxy of <Swig Object of type 'std::deque< FOOTPRINT * >::value_type' at 0x7fc49d2a8bd0> >
<pcbnew.PCB_VIA; proxy of <Swig Object of type 'PCB_VIA *' at 0x7fc49d2a8b70> >

Podívejte se na podobné články podle kategorie: Elektronika KiCad