I’m trying to write a script to load any number of .csv files containing x/y coordinates and draw the tracks on a different layer.
I’m having trouble sorting through the docs. Right now my scripts just default to F.Cu but if possible I’d like it to be able create a copper layer for each imported file.
I would like the code below to create a layer based on fname rather that F.Cu
import pcbnew
import csv
import glob
fout = 'shim-coil.kicad_pcb'
board = pcbnew.BOARD()
def add_track(ri, rf, width):
k = 25400 # convert mils to namometers
track = pcbnew.TRACK(board)
track.SetStart(pcbnew.wxPoint(k*ri[0], k*ri[1]))
track.SetEnd(pcbnew.wxPoint(k*rf[0], k*rf[1]))
track.SetWidth(int(width*k))
board.Add(track)
def load_pts(fname):
"""load trace coordaintes from .tsv file"""
PTS = []
print('Loading "' + fname + '" ...')
with open(fname,'r') as csvfile:
lines = csv.reader(csvfile, delimiter='\t')
for line in lines:
pts = [float(x) for x in line]
PTS.append(pts)
return(PTS)
# Import Tracks
files = glob.glob('./*.tsv')
for fname in files:
PTS = load_pts(fname)
for i in range(0,len(PTS)-1):
add_track(PTS[i], PTS[i+1], 10)
board.Save(fout)
print('Exported "' + fout + '" !')