-
Notifications
You must be signed in to change notification settings - Fork 0
/
__b2a.py
81 lines (74 loc) · 3.02 KB
/
__b2a.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
71
72
73
74
75
76
77
78
79
80
81
namespace = "adazu-skola-";
import bpy,bmesh
class BlendOneLisp():
def __init__(self, opts = {}):
print("INIT")
self.opts = {
"cad3dpoly":False, # use 3d poly command
"cad3face":True, # use 3d face command
"_flipZ":False, # flip Zed axis upon export >> not often needed
"units":1000, #enlarge values if autocad is set in milimeters
"function_call":'zidafabrika03',
"filepath":'zidafabrika03.lsp', #must be lsp for aCad
"resolution":3,
"obj":False
}
self.opts.update(opts)
if self.opts["obj"]:
self.mesh = bmesh.new()
self.mesh.from_mesh(self.opts["obj"].data)
name = self.opts["obj"].name
else:
self.mesh = bmesh.from_edit_mesh(bpy.context.object.data)
name = bpy.context.object.name
self.run()
print("done-" + name)
def run(self):
line = '(defun c:'+self.opts["function_call"]+'()'
for p in self.mesh.faces:
if self.opts["cad3face"] and len(p.verts) > 4:
s="!!!! got extra verts on face"
print("---------\n%s\n---------" % s)
if len(p.verts) == 4 and self.opts["cad3face"]: #3dface can have 4points MAX ( 3point have different spacings )
line+='(command "._3dface" '
for v in p.verts:
exp = ','.join(map(str,map(self.multby,self.prep(v.co))))
line+='"'+exp+'" '
line += '"")'
elif len(p.verts) == 3 and self.opts["cad3face"]: #3dface can have 4points MAX ( 3point have different spacings )
line+='(command "._3dface" '
for v in p.verts:
exp = ','.join(map(str,map(self.multby,self.prep(v.co))))
line+='"'+exp+'" '
line += '"" "")'
elif self.opts["cad3dpoly"]: #fallback to 3d polyline
line+='(command "._3dpoly" '
for v in p.verts:
exp = ','.join(map(str,map(self.multby,self.prep(v.co))))
line+='"'+exp+'" '
# close polyline on first vert
exp = ','.join(map(str,map(self.multby,self.prep(p.verts[0].co))))
line+='"'+exp+'" '
line += '"")'
else:
s="unrendered some data"
print("---------\n%s\n---------" % s)
line += ')'
fo = open(self.opts["filepath"], 'w+')
fo.write( line )
fo.close()
def prep(self, elem): #apply transforms
if self.opts["_flipZ"]:
elem[2] = 0 - elem[2]
return elem
def multby(self, elem):
return round(elem * self.opts["units"],self.opts["resolution"])
for obj in bpy.context.selected_objects:
BlendOneLisp({
"cad3dpoly":False,
"function_call":namespace + obj.name,
"filepath":namespace + obj.name + ".lsp",
"units":1,
"resolution":3,
"obj":obj,
})