# How to import positions?

I have 24 LED’s I want to lay out in a circle (microscope ring light)

By far the easiest way I can think of to do this is use something to generate teh x,y,rot parameters for each one ala the .pos file. Is there a way to easily import this back into the pcb file?

Thanks!

2 Likes

I haven’t tested it, but this snippet of my new script should do the job for placing the Modules

``````import pcbnew
import collections
import math

pcb = pcbnew.GetBoard()

#calc rotation angle (rad) with Position in Clock: float -> float
return math.pi/12*(clockPosition%24)
#calc ratation angle (deg) with Position: float -> float
def calcDegAngleFromClockPosition(clockPosition):
#calc the Position(s) with the Radius and an Angle: float, float -> float/float/wxPoint

def findModules():
modules = {}
for mod in pcb.GetModules():
referenceString = mod.GetReference().encode('utf-8')
print "Found Module: %s" %(referenceString)
modules.update({splitString(referenceString):mod})
#Order The Dictionary
return collections.OrderedDict(sorted(modules.items(), key=lambda t: t[0]))

def getSecondModules(modules_dict):
odict = collections.OrderedDict()
for key, value in modules_dict.items():
if(key[0] == "D" and key[1] in range(1,24+1)):
odict.update({key:value})
return odict

for key, value in modulesSeconds.items():
value.SetOrientation(-(calcDegAngleFromClockPosition(key[1]-1)-90)*10)
print 'Placed: Second %s at %s with rot %s' % (key[0]+str(key[1]), str(value.GetPosition()), str(value.GetOrientation()))

def main():
Modules = findModules()
setPositionSecondRing(getSecondModules(Modules), 40)

if __name__ == '__main__':
main()
``````

I don’t know how you will route it but keep in mind to use module.Pads() to get the pads and pad.GetPosition() to get your start and End Points and pad.GetNetCode() for the netCode. This will be help you with the Tracks. And one Last snippet:

``````def addTrack(startLocation, stopLocation, netCode, layer):
t = pcbnew.TRACK(pcb)