Created
February 14, 2021 13:27
-
-
Save Frank-Buss/2d101f9c0a3b33879eb6a95788baf857 to your computer and use it in GitHub Desktop.
Places components in Pcbnew in KiCad 5.x in a circle
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
# Python script to place components in a circle | |
# based on http://kevincuzner.com/2017/04/28/arranging-components-in-a-circle-with-kicad/ | |
# 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) | |
pcbnew.Refresh() | |
print("Placement finished.") | |
place_circle("D1 D2 D3 D4 D5 D6 D7 D8".split(), 0, (0, 0), 728) |
I am having this issue in Kicad 6 please help
AttributeError: 'BOARD' object has no attribute 'GetModules'
Hi par,
open the affected python script in an editor of your choice and search for
board.GetModules()
and replace it with
board.GetFootprints()
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey Frank, thank you for your script. Unfortunately, it no longer works in KiCad 6. I had to replace the FindModuleByReference function with the FindFootprintByReference function. After that everything was OK again.