Files
Flow_Controller/scripts/move_to_origin.py
2026-05-16 17:57:35 +02:00

34 lines
979 B
Python

# move_to_origin.py
from shapely.affinity import translate
def kikitPostprocess(panel, args):
import pcbnew
# Get bounds from the substrate (Shapely polygon, units in nm)
bounds = panel.boardSubstrate.substrates.bounds # (minx, miny, maxx, maxy)
minx = bounds[0]
miny = bounds[1]
dx = int(-minx)
dy = int(-miny)
offset = pcbnew.VECTOR2I(dx, dy)
# Move all board items (footprints, tracks, drawings, zones)
for fp in panel.board.GetFootprints():
fp.Move(offset)
for track in panel.board.GetTracks():
track.Move(offset)
for drawing in panel.board.GetDrawings():
drawing.Move(offset)
for zone in panel.board.Zones():
zone.Move(offset)
# Translate the substrate geometry (this becomes the Edge.Cuts on save)
dx_nm = -bounds[0]
dy_nm = -bounds[1]
panel.boardSubstrate.substrates = translate(
panel.boardSubstrate.substrates,
xoff=dx_nm,
yoff=dy_nm
)