Rotating from python

I am trying to rotate a board using python.

by doing

elements = chain(pcb.GetTracks(),
pcb.GetFootprints(),
pcb.GetDrawings(),
[pcb.GetArea(i) for i in range(0, pcb.GetAreaCount())])
for e in elements:
e.Rotate(rotAchor, rotDeg)

I can rotate all elements. The problem arises with References, which do not rotate due to the keepupright property.
However, if I do something like
for f in pcb.GetFootprints():
f.Reference().SetKeepUpright(False)

all references get reordiented depending on the footprint orientation.
What should I do to retrieve the orientation when SetKeepUpright is set and reset it when SetKeepUpright is False?
using
for f in pcb.GetFootprints():
g = f.Reference()
ori = g.GetDrawRotation()
g.SetKeepUpright(False)
g.SetTextAngle(ori)
does not work either

All keep upright does is keep actual draw angle in (-90,90] range where actual draw angle is text angle + footprint angle. If it’s outside of that range it adds 180 degrees.

So you probably have to replicate that logic manually by getting raw angles, checking if it would be flipped before the board rotation, disabling keep upright and subtracting 180 from angle of text so that it would match. Then rotation of the footprint will be in sync with rotation of text.

Thank you, the following seems to work

for f in pcb.GetFootprints():

    ref = f.Reference()
    ref.SetKeepUpright(False)

    if ref.GetDrawRotation().IsHorizontal():
        upright = pcbnew.EDA_ANGLE(0, pcbnew.DEGREES_T)
    else:
        upright = pcbnew.EDA_ANGLE(90, pcbnew.DEGREES_T)
    ref.SetTextAngle(upright-f.GetOrientation())
1 Like

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