AttributeError: 'BOARD' object has no attribute 'GetFootprints'

Hi

I want to modify components(footprints?) on the PCB

from pcbnew import *
board = GetBoard()
for fp in board.GetFootprints():
    print(fp.GetName())

I get this error

AttributeError: 'BOARD' object has no attribute 'GetFootprints'

while in the doc, that function clearly exists

image

please help me

thanks

Your kicad version? GetFootprints() is available from 6.0.

just installed it, I am going to give it a try

should I really use footprints ?

I want to set these settings to all components on the PCB

image

how do I change the “Show” & “Layer” values ?

Value() and Reference() methods of the footprint return FP_TEXT object which has SetVisible() and SetLayer().

Also read this Edit Multi Text plugin for KiCad - #4 by paulvdh

nope, they dont

print(dir(board.GetFootprints()[1].GetReference()))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']
print(dir(board.GetFootprints()[1].GetValue()))
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__mul__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', 'capitalize', 'casefold', 'center', 'count', 'encode', 'endswith', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isascii', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'partition', 'removeprefix', 'removesuffix', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'translate', 'upper', 'zfill']

Don’t call GetValue(), call Value(). It’s a different method. Same with Reference().

are there constants for layers ? so far I have to take a wild guess with numbers

board.GetFootprints()[0].Value().SetLayer(0)
board.GetFootprints()[0].Value().SetLayer(6)

also my code is not working

		for fp in board.GetFootprints():
			fp.Reference().SetVisible(False)
			fp.Value().SetVisible(True)

reference is still visible

image

nevermind I use the dialog showed to me by qu1ck

Maybe this can help:

https://docs.kicad.org/doxygen/layer__ids_8h.html#ae0ad6e574332a997f501d1b091c3f53f

PCB_LAYER_ID
enum PCB_LAYER_ID : int

A quick note on layer IDs:

The layers are stored in separate enums so that certain functions can take in the enums as data types and don't have to know about layers from other applications.

Layers that are shared between applications should be in the GAL_LAYER_ID enum.

The PCB_LAYER_ID struct must start at zero for compatibility with legacy board files.

Some functions accept any layer ID, so they start at zero (i.e. F_Cu) and go up to the LAYER_ID_COUNT, which needs to be kept up-to-date if new enums are added. This is the definition of all layers used in Pcbnew.

The PCB layer types are fixed at value 0 through LAYER_ID_COUNT to ensure compatibility with legacy board files.
Enumerator
UNDEFINED_LAYER 	
UNSELECTED_LAYER 	
PCBNEW_LAYER_ID_START 	
F_Cu 	
In1_Cu 	
In2_Cu 	
In3_Cu 	
In4_Cu 	
In5_Cu 	
In6_Cu 	
In7_Cu 	
In8_Cu 	
In9_Cu 	
In10_Cu 	
In11_Cu 	
In12_Cu 	
In13_Cu 	
In14_Cu 	
In15_Cu 	
In16_Cu 	
In17_Cu 	
In18_Cu 	
In19_Cu 	
In20_Cu 	
In21_Cu 	
In22_Cu 	
In23_Cu 	
In24_Cu 	
In25_Cu 	
In26_Cu 	
In27_Cu 	
In28_Cu 	
In29_Cu 	
In30_Cu 	
B_Cu 	
B_Adhes 	
F_Adhes 	
B_Paste 	
F_Paste 	
B_SilkS 	
F_SilkS 	
B_Mask 	
F_Mask 	
Dwgs_User 	
Cmts_User 	
Eco1_User 	
Eco2_User 	
Edge_Cuts 	
Margin 	
B_CrtYd 	
F_CrtYd 	
B_Fab 	
F_Fab 	
User_1 	
User_2 	
User_3 	
User_4 	
User_5 	
User_6 	
User_7 	
User_8 	
User_9 	
Rescue 	
PCB_LAYER_ID_COUNT 	

Definition at line 58 of file layer_ids.h.
{
 UNDEFINED_LAYER = -1,
 UNSELECTED_LAYER = -2,
 
 PCBNEW_LAYER_ID_START = 0,
 F_Cu = PCBNEW_LAYER_ID_START,
 In1_Cu,
 In2_Cu,
 In3_Cu,
 In4_Cu,
 In5_Cu,
 In6_Cu,
 In7_Cu,
 In8_Cu,
 In9_Cu,
 In10_Cu,
 In11_Cu,
 In12_Cu,
 In13_Cu,
 In14_Cu,
 In15_Cu,
 In16_Cu,
 In17_Cu,
 In18_Cu,
 In19_Cu,
 In20_Cu,
 In21_Cu,
 In22_Cu,
 In23_Cu,
 In24_Cu,
 In25_Cu,
 In26_Cu,
 In27_Cu,
 In28_Cu,
 In29_Cu,
 In30_Cu,
 B_Cu, // 31
 
 B_Adhes,
 F_Adhes,
 
 B_Paste,
 F_Paste,
 
 B_SilkS,
 F_SilkS,
 
 B_Mask,
 F_Mask, // 39
 
 Dwgs_User,
 Cmts_User,
 Eco1_User,
 Eco2_User,
 Edge_Cuts,
 Margin, // 45
 
 B_CrtYd,
 F_CrtYd,
 
 B_Fab,
 F_Fab, // 49
 
 // User definable layers.
 User_1,
 User_2,
 User_3,
 User_4,
 User_5,
 User_6,
 User_7,
 User_8,
 User_9,
 
 Rescue, // 59
 
 // Four reserved layers (60 - 63) for future expansion within the 64 bit integer limit.
 
 PCB_LAYER_ID_COUNT
};
1 Like

pcbnew.F_Cu etc. For some reason they don’t all follow the same naming conventions. (What would follow some naming convention in pcbnew API?)

EDIT: I have written some documentation for my own internal use in Plugin howtos · Wiki · eelik-kicad / KiCad Documentation · GitLab. Maybe it can help. The layer constants are documented there, too.

4 Likes

That’s really helpful. Thanks for sharing.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.