#!/usr/bin/env python3 """ Move board and all components to origin (0,0) Run in KiCad PCB Editor: Tools → Scripting Console Then: exec(open('scripts/move_to_origin.py').read()) """ import pcbnew board = pcbnew.GetBoard() # Get current board origin from edge cuts bbox = board.GetBoardEdgesBoundingBox() offset_x = bbox.GetX() offset_y = bbox.GetY() print(f"Current board origin: ({pcbnew.ToMM(offset_x):.2f}, {pcbnew.ToMM(offset_y):.2f}) mm") if offset_x == 0 and offset_y == 0: print("Board is already at origin!") else: # Move all footprints for fp in board.GetFootprints(): pos = fp.GetPosition() new_pos = pcbnew.VECTOR2I(pos.x - offset_x, pos.y - offset_y) fp.SetPosition(new_pos) # Move all drawings (including board outline) for drawing in board.GetDrawings(): if hasattr(drawing, 'Move'): drawing.Move(pcbnew.VECTOR2I(-offset_x, -offset_y)) # Move all tracks for track in board.GetTracks(): track.Move(pcbnew.VECTOR2I(-offset_x, -offset_y)) # Move all zones for zone in board.Zones(): zone.Move(pcbnew.VECTOR2I(-offset_x, -offset_y)) print(f"Moved everything by ({-pcbnew.ToMM(offset_x):.2f}, {-pcbnew.ToMM(offset_y):.2f}) mm") print("Board is now at origin (0, 0)") pcbnew.Refresh() print("\nDone! Save (Ctrl+S), delete all tracks, then run place_6hp.py")