Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/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()