Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Places components in Pcbnew in KiCad 5.x in a circle
# Python script to place components in a circle
# based on
# but ported to Python 3 and KiCad 5.x
# You can just open "Tools->Scripting Console" and paste the whole thing.
# Needs to be in 3 parts: first the import line, then the function definition (and hit enter twice),
# and finally the place_circle call.
# Since refs can't have spaces in the name, I also simplified the list creation with the split function.
import math, pcbnew
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 = pcbnew.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(pcbnew.wxPoint(pcbnew.FromMils(xmils), pcbnew.FromMils(ymils)))
part.SetOrientation(angle * -10)
if hide_ref is not None:
part.Reference().SetVisible(not hide_ref)
print("Placement finished.")
place_circle("D1 D2 D3 D4 D5 D6 D7 D8".split(), 0, (0, 0), 728)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment