Forked from vlad-ivanov-name/Kicad circular layout
Created
September 4, 2018 09:33
-
-
Save rsrg/671ac8e32f325847f8af78ed5b612751 to your computer and use it in GitHub Desktop.
Kicad circular layout
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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