-
Notifications
You must be signed in to change notification settings - Fork 6
/
OpenSCADdxf.save.py
70 lines (61 loc) · 2.07 KB
/
OpenSCADdxf.save.py
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
65
66
67
68
69
70
def importEZDXFface(filename,layer=None,doc=None):
import ezdxf
import Part
print(f"import EZDXFface layer = {layer}")
fdoc = doc or FreeCAD.activeDocument()
ddoc = ezdxf.readfile(filename)
msp = ddoc.modelspace()
lines = msp.query('LINE')
splines = msp.query('SPLINE')
plines = msp.query('POLYLINE')
lwplines = msp.query('LWPOLYLINE')
faces=list()
face_l=None
face_p=None
face_lwp=None
if len(lines)>0:
elements = []
for l in lines:
if l.dxf.start != l.dxf.end:
poly = Part.makeLine(tuple(l.dxf.start), tuple(l.dxf.end)) #makes Edge object
else:
print("START==END")
#poly = Part.Wire(poly) #makes Wire object
elements.append(poly) #creates list of Wires for use in Part.Face
face_l=Part.Wire(elements) #L
'''
if len(splines)>0:
for s in splines:
print("SPLINE")
#s.control_points
#s.fit_points
'''
if len(plines)>0:
for p in plines:
#print("POLYLINE")
verts = p.vertices
verts = [tuple(v.dxf.location) for v in verts]
if p.is_closed:
verts += [verts[0]]
poly = Part.makePolygon(verts)
face_p=poly #P
if len(lwplines)>0:
elements=[]
for lwp in lwplines:
#print("LWPOLYLINE")
with lwp.points("xy") as points: #xyseb
for p in points: #TODO: vectorize??
poly = tuple([p[0], p[1], 0])
elements.append(poly)
poly = Part.makePolygon(elements) #makes a Wire
face_lwp=poly #LWP
if face_l != None:
faces.append(face_l)
if face_p != None:
faces.append(face_p)
if face_lwp != None:
faces.append(face_lwp)
faces=Part.Face(faces)
#if (len(ddoc.entities) != len(lines)+len(splines)+len(plines)+len(swplines):
# print("NOT ALL ENTITIES DEALT WITH")
return faces