Folks I’m trying to change the layer of pads for a module with the following code:
import sys
import pcbnew
from shutil import copyfile
file_in = 'test1.kicad_pcb'
file_out = 'test2.kicad_pcb'
copyfile(file_in, file_out)
board = pcbnew.LoadBoard(file_out)
pctl = pcbnew.PLOT_CONTROLLER(board)
popt = pctl.GetPlotOptions()
layertable = {}
for i in range(50):
name = board.GetLayerName(i)
if name != "BAD INDEX!":
layertable[name]=i
modref = "LDFM1"
mod = board.FindModuleByReference(modref)
for pad in mod.Pads():
print("pad {}({}) on {}({}) at {},{} shape {} size {},{} {}"
.format(pad.GetPadName(),
pad.GetNet().GetNetname(),
mod.GetReference(),
mod.GetValue(),
pad.GetPosition().x, pad.GetPosition().y,
pad.GetShape(),
pad.GetSize().x, pad.GetSize().y,
board.GetLayerName(pad.GetLayer())
))
print ("\nshow change\n")
for pad in mod.Pads():
# I would have expected this line to change pad layer, it does in the following print statement
pad.SetLayer(layertable["Bottom"])
print("pad {}({}) on {}({}) at {},{} shape {} size {},{} {}"
.format(pad.GetPadName(),
pad.GetNet().GetNetname(),
mod.GetReference(),
mod.GetValue(),
pad.GetPosition().x, pad.GetPosition().y,
pad.GetShape(),
pad.GetSize().x, pad.GetSize().y,
board.GetLayerName(pad.GetLayer())
))
pcbnew.SaveBoard(file_out, board)
The output of the second for loop shows the pads are on a new layer, but the pads are not changed to the saved file (test2.kicad_pcb). Any suggestions?