I know about array and polar placement methods. What I want to do is calculate the placement of components, then automatically place the components based on my calculations.
.csv List could be like:
U1,12.5,15.045,90,front
U2,16.5,14.355,120,front
U3,20.5,13.890,245,back
The components would already be loaded into KiCad via the normal schematic -> KiCad interface. I just want an easy way to set their position and orientation based on some complex math calculated in another program. When there are a few components, the absolute placement dialog works, but I want to place hundreds.
I find it no problem to auto generate simple lines, arcs, etc, then insert them into the KiCad file. Modules, which parts are stored as, are complex and a pain to create/edit simply with scripts. I could spend the effort to figure out how to edit them, but is there an easier way?
I thought I would have a go since I might find it useful for a current project.
This handles a single footprint, and you probably have a more efficient way to handle >1, but that is standard Python.
from pcbnew import *
"""
To run from KiCad script console in pcbnew:
1. Open the console with Tools->Scripting Console
2. Save open files before running script!
3. type the following command in the console window:
execfile ("c:/python_progs/test_pcb/move_footprint.py")
change "c:/python_progs/test_pcb/" to where you stored "move_footprint.py".
Bob Cousins 2019
"""
def MoveFootprint(Filename, ref, x, y, rot, layer):
if Filename:
my_board = pcbnew.LoadBoard (Filename)
else:
my_board = GetBoard()
for module in my_board.GetModules():
if module.GetReference() == ref:
print ("module ref %s %s" % ( module.GetReference(), my_board.GetLayerName(module.Reference().GetLayer())))
module.SetPosition (wxPointMM(x,y))
module.SetOrientation( rot * 10.0)
if module.IsFlipped() and layer == 'top':
module.Flip(wxPointMM(x,y))
elif not module.IsFlipped() and layer == 'bottom':
module.Flip(wxPointMM(x,y))
#
MoveFootprint(None, "S2", 40, 10, 90, 'bottom')
Refresh()