-
Notifications
You must be signed in to change notification settings - Fork 247
/
sheets.py
executable file
·74 lines (68 loc) · 2.32 KB
/
sheets.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
#!/usr/bin/env python
from __future__ import print_function
import os
import openscad
import InkCL
import shutil
import sys
from dxf import *
from set_machine import *
from time import *
source_dir = "scad"
def sheets(machine, parts = None):
#
# Make the target directory
#
target_dir = machine + "/sheets"
if os.path.isdir(target_dir):
shutil.rmtree(target_dir)
sleep(0.1)
os.makedirs(target_dir)
else:
os.makedirs(target_dir)
#
# Set the target machine
#
set_machine(machine)
#
# Find all the scad files
#
for filename in os.listdir(source_dir):
if filename[-5:] == ".scad":
#
# find any modules ending in _dxf
#
for line in open(source_dir + "/" + filename, "r").readlines():
words = line.split()
if len(words) and words[0] == "module":
module = words[1].split('(')[0]
if module[-4:] == "_dxf" and (not parts or (module[:-4] + ".dxf") in parts):
#
# make a file to use the module
#
dxf_maker_name = target_dir + "/" + module + ".scad"
f = open(dxf_maker_name, "w")
f.write("use <../../%s/%s>\n" % (source_dir, filename))
f.write("%s();\n" % module);
f.close()
#
# Run openscad on the created file
#
base_name = target_dir + "/" + module[:-4]
dxf_name = base_name + ".dxf"
openscad.run("-o", dxf_name, dxf_maker_name)
#
# Make SVG drill template
#
dxf_to_svg(dxf_name)
#
# Make PDF for printing
#
InkCL.run("-f", base_name + ".svg", "-A", base_name + ".pdf")
os.remove(dxf_maker_name)
if __name__ == '__main__':
if len(sys.argv) > 1:
sheets(sys.argv[1], sys.argv[2:])
else:
print("usage: sheets dibond|mendel|sturdy|huxley|your_machine [part.dxf ...]")
sys.exit(1)