Hi all, first time poster here so apologies if I’m in the wrong place.
I’m having issues using the Python APIs to swap out a footprint for a pair of footprints - I want to replace a single footprint with two different footprints, and move/rotate the new footprints a bit to keep them in the correct spots. Here’s my code:
I have to run this in a silly line-by-line fashion in the shell otherwise it executes the first line and nothing else (not sure what’s up there) but where the real problems start is the SetFPID call doesn’t seem to actually replace the footprint. I can see that the object in the PCB references the new footprint, but it is visually not that footprint. I have to go to ‘Update footprint’ from its properties for the change to take effect. Also, creating the LED module doesn’t seem to work at all, but I’m at a loss as to what to do with just the docs to guide me. Please let me know if there’s just a function I’m missing or if I’m going about this entirely the wrong way. Thanks.
SetFPID will not change footprint, it will just change the reference in existing footprint object to point to new footprint ID.
If you want to actually swap footprints you need to create new Module object probably by loading it from library, add it to board using board.Add() and remove old object.
Thanks for the reply, although board.Add(MODULE module) doesn’t seem to do anything, and I can’t find that method in the docs at all. Could there be something else I’m missing?
Refresh is great, thanks for that. I was using SaveBoard previously but I wasn’t seeing my new modules in the new file, and I still don’t see them after refreshing. Here’s my code now:
I’ve tried calling IsPlaced() before and after the board.Add calls but they both return false. Am I missing a call that actually does the placement maybe?
You don’t see them because you are adding empty module objects. Just because you set fpid to something will not make that object load the footprint from library, you need to create your MODULE objects using FootprintLoad(). After you loaded it once you can clone them using MODULE(anothermodule) which is a bit faster.
board = pcbnew.LoadBoard("E:\\Path\\To\\Board")
This creates new board object, it is not the same board object that pcbnew window has. That’s why changes to it will not reflect in pcbnew.
If you want to get the board object that pcbnew window has use pcbnew.GetBoard()