Skip to content

Instantly share code, notes, and snippets.

@kcuzner
Created February 12, 2023 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kcuzner/e3160cd4f09a4ccf8a9d62e5c00f332e to your computer and use it in GitHub Desktop.
Save kcuzner/e3160cd4f09a4ccf8a9d62e5c00f332e to your computer and use it in GitHub Desktop.
Arranging components in a circle with kicad
#!/usr/bin/env python2
# Random placement helpers because I'm tired of using spreadsheets for doing this
#
# Kevin Cuzner
import math
from pcbnew import *
def place_circle(refdes, start_angle, center, radius, component_offset=0, hide_ref=True, lock=False):
"""
Places components in a circle
refdes: List of component references
start_angle: Starting angle
center: Tuple of (x, y) mils of circle center
radius: Radius of the circle in mils
component_offset: Offset in degrees for each component to add to angle
hide_ref: Hides the reference if true, leaves it be if None
lock: Locks the footprint if true
"""
pcb = GetBoard()
deg_per_idx = 360 / len(refdes)
for idx, rd in enumerate(refdes):
part = pcb.FindModuleByReference(rd)
angle = (deg_per_idx * idx + start_angle) % 360;
print "{0}: {1}".format(rd, angle)
xmils = center[0] + math.cos(math.radians(angle)) * radius
ymils = center[1] + math.sin(math.radians(angle)) * radius
part.SetPosition(wxPoint(FromMils(xmils), FromMils(ymils)))
part.SetOrientation(angle * -10)
if hide_ref is not None:
part.Reference().SetVisible(not hide_ref)
print "Placement finished. Press F11 to refresh."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment