Ver nuestro post anterior Cómo obtener la lista de todos los footprints usando la API de Python del plugin pcbnew de KiCAD y Cómo obtener todos los footprints seleccionados usando la API de Python del plugin pcbnew de KiCAD para más información sobre cómo obtener un objeto footprint.
Una vez que tienes un objeto pcbnew.FOOTPRINT, puedes obtener sus elementos gráficos (que son básicamente las líneas, rectángulos, círculos etc en el footprint - pero no las etiquetas de serigrafía) usando
footprint_graphical_elements.py
footprint.GraphicalElements()Ejemplo:
footprint_graphical_iter.py
for graphical_element in footprint.GraphicalItems():
print(graphical_element)Salida:
output.txt
<pcbnew.FP_TEXT; proxy of <Swig Object of type 'FP_TEXT *' at 0x7fc47f2c41e0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f0f10b0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c69d0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c6d30> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f0f10e0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c6cd0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c6ca0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f0f38d0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c68b0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c41e0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f0f10b0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c69d0> >
<pcbnew.FP_SHAPE; proxy of <Swig Object of type 'FP_SHAPE *' at 0x7fc47f2c6d30> >Puedes filtrarlos usando
filter_graphical_items.py
fp_texts: list[pcbnew.FP_TEXT] = [
item for footprint in selected_footprint.GraphicalItems()
if type(item).__name__ == 'FP_TEXT'
]
fp_shapes: list[pcbnew.FP_SHAPE] = [
item for footprint in selected_footprint.GraphicalItems()
if type(item).__name__ == 'FP_SHAPE'
]
Echa un vistazo a artículos similares por categoría:
Electrónica KiCad
Si este artículo te ha ayudado, considera invitarme a un café o hacer una donación vía PayPal para apoyar la investigación y publicación de nuevos artículos en TechOverflow