Hi!
In pcbnew, when you update a footprint by clicking on a footprint, then selecting ‘Change Footprint(s)’ and ‘Apply’ the footprints gets updated to the latest version in the footprint library. I was getting annoyed that this also updates the reference designator so I wrote the following code snippets that allow to save and restore the position of the reference designator. It may be of use to someone:
import pcbnew
pcb = pcbnew.GetBoard()
# save reference designator position/orientation
refdict = {}
for mod in pcb.GetModules():
ref = mod.GetReference() # the reference, i.e. u"R1"
reftxt = mod.Reference() # the reference object printed on the silkscreen
pos0 = reftxt.GetPos0()
orientation = reftxt.GetOrientation()
refdict[ref] = pos0, orientation
# restore reference designator position/orientation
for mod in pcb.GetModules():
ref = mod.GetReference() # the reference, i.e. u"R1"
reftxt = mod.Reference() # the reference object printed on the silkscreen
pos0, orientation = refdict[ref]
reftxt.SetPos0(pos0)
reftxt.SetOrientation(orientation)
To use this open the scripting console and copy-paste the first part. Then update the footprints on the board, and lastly copy-past the last part of the script.
If someone knows how to update a footprint using the scripting interface (I was unsuccessful), please let me know and I will update the script to make it fully automated