# KiCAD parametric component placement

I need to place components in a circle of a certain diameter, with a certain pitch, and angled evenly.

Is possible to do it in KiCAD automatically?

## 3 Answers

No, but you can do it "manually" for any size and number in PCBNew using the magic of polar coordinates. Say you wanted six LED's aligned to the circumference of a 40mm diameter circle:

• Move all six of the parts to the top-left corner of the page (0,0).
• Press the "Polar Coordinates" button on the left bar. Notice that the bottom bar middle now reads in polar coordinates (radius r, angle theta.)
• 360°/6 = 60° for each angle. Angle ($$\\theta\$$) convention in PCBNew is: 0° is the 3 o'clock position, 90° = noon, 180° = 9 o'clock, and after this it inverts (-180°), -90° at the 6 o'clock position, and back to -0.
• $$\r = \frac{1}{2}d\$$ , so radius r = 20mm.
• Unfortunately, part positions cannot be entered in polar notation. We will estimate using the polar read-out in the bottom statusbar.
• Click M over the stack of parts, use the arrow keys to position D1 such that r is 2.0 and theta is 0. Click to place D1.
• Click M over the remaining parts, move D2 such that r is ~2.0 and theta is ~60. It will help to make the snap grid very small.
• Click M and move D3 r = ~2.0 and theta = ~120.
• Click M and move D4 r = 2.0 and theta = 180 or -180.
• Click M and move D5 r = ~2.0 and theta = -120.
• Click M and move D6 r = ~2.0 and theta = -60.
• Click E over each LED and enter their rotation angles (0,60,120,180,240,300.) This is the result: Now drag a box around the whole group and move with M.

To calculate Cartesian coordinates (polar button not clicked, for accurate X,Y positions) Trigonometry must be used. Negative theta values will also work here. Perhaps this will help with a python solution:

• To convert polar (radius r, angle $$\\theta\$$) to Cartesian (x,y): $$\\quad x=r\cdot \cos \left(\theta \right)\quad \:y=r\cdot \sin \left(\theta \right)\$$
• Element 1, 0°: $$\\quad\cos\left(0\right)\cdot20 = 20\quad\sin\left(0\right)\cdot20 = 0\quad\$$ (20,0), rotate the part 0°
• Element 2, 60°: $$\\quad\cos\left(60\right)\cdot20 = 10\quad\sin\left(60\right)\cdot20 = 17.32\quad\$$ (10,17.32), rotate 60°
• Element 3, 120°: $$\\quad\cos\left(120\right)\cdot20 = -10\quad\sin\left(120\right)\cdot20 = 17.32\quad\$$ (-10,17.32), rotate 120°
• Element 4, 180°: $$\\quad\cos\left(180\right)\cdot20 = -20\quad\sin\left(180\right)\cdot20 = 0\quad\$$ (-20,0), rotate 180°
• Element 5, 240°: $$\\quad\cos\left(240\right)\cdot20 = -10\quad\sin\left(240\right)\cdot20 = -17.32\quad\$$ (-10,-17.32), rotate 240°
• Element 6, 300°: $$\\quad\cos\left(300\right)\cdot20 = 10\quad\sin\left(300\right)\cdot20 = -17.32\quad\$$ (10,-17.32), rotate 300°

This may not be fast nor easy, but it's precise.

Note many calculators differ on how trig functions are entered. On the Windows 10 scientific calculator for instance, these must be entered in this order: 60 COS * 20 =.

Nope, not without knowing some python. (you can write a script yourself which does it)

Otherwise you are left to do the same as the rest of us; Excel sheet, some excel math, and then a ton of manual work putting all the exact coordinates in the footprint data for each footprint.

If you want to look into writing a python script to solve the problem for you then here are some hints to get you started; All KiCad files (the .kicad_pcb file included) are plain-text files. If you open the .kicad_pcb file in a text editor (such as Notepad++ for instance) then you will be able to see the whole pcb layout described in plaintext, and it is easy to read..

If you scroll down into the text file (the .kicad_pcb file) you will start finding stuff like this;

  (module MYCOMPANYNAME:MYMODULENAME (layer F.Cu) (tedit 5C925A16) (tstamp 5CAD3543)
(at 92.5 95.25)
(path /5D633F7C)
(attr smd)
(fp_text reference J3 (at 0 6.604) (layer F.SilkS)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_text value 87832-0406 (at 0 -7.112) (layer F.Fab)
(effects (font (size 1 1) (thickness 0.15)))
)
(fp_line (start -0.762 4.191) (end -1.27 4.191) (layer F.SilkS) (width 0.15))
(fp_line (start -1.016 3.81) (end -0.762 4.191) (layer F.SilkS) (width 0.15))


Pay attention to the line that says; (at 92.5 95.25), this is the position of the specific module MYMODULENAME.

If you know a bit of python then it is fairly easy to write a script which opens the .kicad_pcb file, finds the specific modules that you want to place in a circle, and writes the correct positions to these.

But this script would either have to be written specifically to your use case, or be written more generically, in which case it is a whole SW project on its own (:

• I am not sure I understand your answer: you say it is not possible, then proceed to describe how it is possible. Either you explain how to do that with a python script, or you don't answer at all. – Vladimir Cravero Aug 14 '19 at 17:34
• @VladimirCravero what an ignorant and unnecessary response. He asks if it is possible to do it automatically in KiCad, and I answer; No, it is not. (because there is no build in function to do this).. You can, as I said, do it by writing a python script (for that specific task) but I would not consider this an "automatic way to do it in KiCad" and hence I did not attempt to write a python script for him to solve the task. – Vinzent Aug 14 '19 at 17:39
• I did never mention that you needed to write the script for him, I was just wondering why you did not write "yes", instead of "no". I guess that in that sense my comment can be considered ignorant, since I ignored why you did that. A yes, a link to the docs, and the suggestion to do it with excel is what I would have written, I was just curious about your reasoning; I am sorry if my comment came through as rude, but I was just genuinely curious. – Vladimir Cravero Aug 14 '19 at 17:47
• @VladimirCravero okay, yeah your comment did come across as rude to me. But I understand now what you meant. I still consider "No" the correct answer to the question that he posed, however I have added some more information to my answer in order to try and make it more helpful (:. – Vinzent Aug 14 '19 at 17:52

A bit late to the party but there are ways to do what you want without math or python. All below assumes version 5.1 but similar tools existed in previous versions as well.)

# Option 1 the array tool:

Sadly this tool does not allow one to use any other origin than the main coordinate system. (this is why this is a bit more complex) It further is not an option if you have different footprints to align.

Put your first part correctly rotated with distance radius relative to the main coordinate origin (top left corner of the worksheet, example with 0 rotation at x= radius, y=0)

right click on it and select array tool. Switch to polar array and enter your intended settings (number of parts, should it rotate, ...) and press ok.

You will now have a circle of parts. Change their references manually to fit the schematic and possibly delete the duplicates that were originally placed by the update from schematic tool. Run that tool again but tell kicad to use the reference designator (re-associate by reference) to ensure both schematic and pcb are in sync.

# Option 2: move exactly tool

A bit more work but does not require reassociating the footprints.

Place all your components where the first one should end up and rotated like you want them.

Place the auxiliary coordinate origin at your intended center.

Right click on the first one and select move exactly (crtl+m) Select rotate around drill and place origin (this selects the auxilary coordinate system) Enter the intended rotation for this part and click ok. Repeat for all other parts.