forked from ejbantz/3dPrinterCamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
views.py
70 lines (56 loc) · 2.19 KB
/
views.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
#!/usr/bin/env python
import os
import sys
import shutil
import openscad
def views(machine):
scad_dir = "views"
render_dir = machine + os.sep + "views"
if not os.path.isdir(render_dir):
os.makedirs(render_dir)
#
# Set the target machine
#
f = open("scad/conf/machine.scad","wt")
f.write("include <%s_config.scad>\n" % machine);
f.close()
#
# List of individual part files
#
scads = [i for i in os.listdir(scad_dir) if i[-5:] == ".scad"]
for scad in scads:
scad_name = scad_dir + os.sep + scad
png_name = render_dir + os.sep + scad[:-4] + "png"
for line in open(scad_name, "r").readlines():
words = line.split()
if len(words) > 10 and words[0] == "//":
cmd = words[1]
if cmd == "view" or cmd == "assembled" or cmd == "assembly":
w = int(words[2]) * 2
h = int(words[3]) * 2
dx = -float(words[4])
dy = -float(words[5])
dz = -float(words[6])
rx = 360.0 - float(words[7]) + 90
ry = 360.0 - float(words[8])
rz = 360.0 - float(words[9])
d = float(words[10])
camera = "%.2f,%.2f,%.2f,%.2f,%.2f,%.2f,%.2f" % (dx, dy, dz, rx, ry, rz, d)
exploded = "0"
if cmd == "assembly":
exploded = "1"
if cmd == "assembled":
png_name = png_name.replace("assembly","assembled")
if not os.path.isfile(png_name) or os.path.getmtime(png_name) < os.path.getmtime(scad_name):
openscad.run("--projection=p",
("--imgsize=%d,%d" % (w, h)),
"--camera=" + camera,
"-D$exploded=" + exploded,
"-o", png_name, scad_name)
print
if __name__ == '__main__':
if len(sys.argv) > 1:
views(sys.argv[1])
else:
print "usage: views [mendel|sturdy|your_machine]"
sys.exit(1)