#!/usr/bin/env python3 """ python 3.6.8 """ import ezdxf from pykicad import pcb import numpy as np class importer(): def __init__(self,dxf_file,layer,width=None,board=None): self.dwg=ezdxf.readfile(dxf_file) self.msp=self.dwg.modelspace() self.layer=layer self.width=width if board!=None: self.board=pcb.Pcb.from_file(board) self.draw_pcb() def all(self): self.line_class() self.poly_class() def line_class(self): startlist=[] endlist=[] line_list=[] for e in self.msp.query('LINE'): startlist.append(e.dxf.start[:2]) endlist.append(e.dxf.end[:2]) for i in range(len(startlist)): l=pcb.GrLine(startlist[i],endlist[i],self.layer,self.width) line_list.append(l) return line_list def poly_class(self): pts_list=[] ply_list=[] for e in self.msp.query('LWPOLYLINE'): pts_list.append(e.get_points()) for pts_set in pts_list: p=pcb.GrPolygon(pts_set,self.layer,self.width) ply_list.append(p) return ply_list def draw_pcb(self): self.board.lines+=self.line_class() self.board.polygons+=self.poly_class()