2012-03-16 00:31:47 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2012-03-12 01:13:07 +00:00
|
|
|
import os
|
2012-03-12 22:55:27 +02:00
|
|
|
import openscad
|
2012-04-01 14:08:44 +01:00
|
|
|
import InkCL
|
2012-03-12 01:13:07 +00:00
|
|
|
import shutil
|
|
|
|
import sys
|
|
|
|
from dxf import *
|
|
|
|
|
|
|
|
source_dir = "scad"
|
|
|
|
|
|
|
|
def sheets(machine):
|
|
|
|
#
|
|
|
|
# Make the target directory
|
|
|
|
#
|
|
|
|
target_dir = machine + "/sheets"
|
|
|
|
if os.path.isdir(target_dir):
|
2012-11-15 17:45:30 +00:00
|
|
|
try:
|
|
|
|
shutil.rmtree(target_dir)
|
2012-11-17 10:33:00 +00:00
|
|
|
os.makedirs(target_dir)
|
2012-11-15 17:45:30 +00:00
|
|
|
except:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
os.makedirs(target_dir)
|
2012-03-12 01:13:07 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# Set the target machine
|
|
|
|
#
|
|
|
|
f = open("scad/conf/machine.scad","wt")
|
|
|
|
f. write("include <%s_config.scad>\n" % machine);
|
|
|
|
f.close()
|
|
|
|
|
|
|
|
#
|
|
|
|
# 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":
|
|
|
|
#
|
|
|
|
# make a file to use the module
|
|
|
|
#
|
|
|
|
dxf_maker_name = target_dir + "/" + module + ".scad"
|
|
|
|
f = open(dxf_maker_name, "w")
|
2012-03-27 18:12:04 +01:00
|
|
|
f.write("use <../../%s/%s>\n" % (source_dir, filename))
|
2012-03-12 01:13:07 +00:00
|
|
|
f.write("%s();\n" % module);
|
|
|
|
f.close()
|
|
|
|
#
|
|
|
|
# Run openscad on the created file
|
|
|
|
#
|
2012-04-01 14:08:44 +01:00
|
|
|
base_name = target_dir + "/" + module[:-4]
|
|
|
|
dxf_name = base_name + ".dxf"
|
2012-03-12 22:55:27 +02:00
|
|
|
openscad.run("-o", dxf_name, dxf_maker_name)
|
2012-04-01 14:08:44 +01:00
|
|
|
#
|
|
|
|
# Make SVG drill template
|
|
|
|
#
|
2012-03-12 01:13:07 +00:00
|
|
|
dxf_to_svg(dxf_name)
|
2012-04-01 14:08:44 +01:00
|
|
|
#
|
|
|
|
# Make PDF for printing
|
|
|
|
#
|
|
|
|
InkCL.run("-f", base_name + ".svg", "-A", base_name + ".pdf")
|
2012-03-12 01:13:07 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
sheets(sys.argv[1])
|
|
|
|
else:
|
|
|
|
print "usage: sheets [mendel|sturdy|your_machine]"
|
|
|
|
sys.exit(1)
|