Skip to content

Instantly share code, notes, and snippets.

@vlad-ivanov-name
Last active February 27, 2021 20:43
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save vlad-ivanov-name/81d8fa2b172437fef7c1 to your computer and use it in GitHub Desktop.
Save vlad-ivanov-name/81d8fa2b172437fef7c1 to your computer and use it in GitHub Desktop.
Kicad circular layout
"""
Usage: open pcbnew and select Tools — Scripting console
Enter the following and press enter:
execfile("path/to/script.py")
Script settings can be adjusted below
"""
import pcbnew
import sys
import re
import math
from pcbnew import wxPoint
from math import *
# Units: mm, degrees
centerX = 100
centerY = 100
sizeX = 100
sizeY = 100
angleShift = 0
refFilter = 'D[0-9]+'
# ----------
regex = re.compile(refFilter)
pcb = pcbnew.GetBoard()
modules = pcb.GetModules()
moduleCount = 0
for module in modules:
reference = module.GetReference()
if regex.match(reference):
moduleCount += 1
index = 0
scaleFactor = 1000000
moduleAngle = - (360 * 10 / moduleCount)
for module in modules:
reference = module.GetReference()
if not regex.match(reference):
continue
angle = (pi * 2 / moduleCount) * index
pointX = centerX + (sizeX / 2) * cos(angle)
pointY = centerY + (sizeY / 2) * sin(angle)
point = wxPoint(pointX * scaleFactor, pointY * scaleFactor)
module.SetPosition(point)
module.SetOrientation(moduleAngle * index + angleShift * 10)
index += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment