here is a sample code

import pcbnew, re
board = pcbnew.GetBoard()
modules = board.GetModules()

interested_modules=[]

for mod in modules:
    print(mod.GetReference())

diode_r = re.compile(r".*D\d+")


for mod in modules:
    if diode_r.match(mod.GetReference()):
        interested_modules.append(mod)


pklfile = "D:\projects\circleproblem\\triangular_points.txt"

with open(pklfile, 'r') as fd:
    lines = fd.readlines()

points=[]

for line in lines:
    if line[-1]=='\n':
        line=line[:-1]
    splitted = line.split(' ')
    x = float(splitted[0])
    y = float(splitted[1])
    points.append([x,y])

# SetPosition

scale= 1000000

for i, point in enumerate(points):
    selmod = interested_modules[i]
    # x,y = point
    x,y = point
    x *= scale
    y *= scale
    wxp = pcbnew.wxPoint(x,y)
    
    selmod.SetPosition(wxp)

# update the gui to show updated positions
pcbnew.Refresh()

The last line does the trick of updating the changes made to be fully applied on to the pcbnew workscreen.

Categories: kicad

0 Comments

Leave a Reply

Your email address will not be published.