pcbnew SetLayer() always errors out
Description
Can't set a specific layer to place a footprint with pcbnew Kicad 7 API. With the given code, it always prints "Invalid layer or layer not enabled. Please enter a valid layer."
Steps to reproduce
import pcbnew
board = pcbnew.GetBoard()
library_path = "C:\\Program Files\\KiCad\\7.0\\share\\kicad\\footprints\\Resistor_SMD.pretty"
component_name = "R_0402_1005Metric"
plugin_type = pcbnew.IO_MGR.GuessPluginTypeFromLibPath(library_path)
io_mgr = pcbnew.IO_MGR.PluginFind(plugin_type)
footprint = io_mgr.FootprintLoad(library_path, component_name)
# Create a dictionary to map layer names to their IDs
layer_map = {
"
F.Cu
": 0,
"
B.Cu
": 31
}
# Ask for layer and set it
while True:
layer_input = input("Enter the layer for the resistor (e.g.,
F.Cu
for the front,
B.Cu
for the back): ").strip()
`if layer_input in layer_map and board.IsLayerEnabled(layer_map[layer_input]):`
`footprint.SetLayer(layer_map[layer_input])`
`break`
`else:`
`print("Invalid layer or layer not enabled. Please enter a valid layer.")`
# Add the footprint to the board
board.Add(footprint)
print(f"Resistor of {value} added to {layer_input} layer.")
KiCad Version
Application: KiCad x64 on x64
Version: 7.0.7, release build
Libraries: wxWidgets 3.2.2 FreeType 2.12.1 HarfBuzz 6.0.0 FontConfig 2.14.1 libcurl/7.88.1-DEV Schannel zlib/1.2.13
Platform: Windows 11 (build 22621), 64-bit edition, 64 bit, Little endian, wxMSW
Build Info: Date: Aug 14 2023 02:42:39 wxWidgets: 3.2.2 (wchar_t,wx containers) Boost: 1.81.0 OCC: 7.7.1 Curl: 7.88.1-DEV ngspice: 40 Compiler: Visual C++ 1936 without C++ ABI
Build settings: KICAD_SPICE=ON