-
Notifications
You must be signed in to change notification settings - Fork 9
/
exp2exp.py
executable file
·100 lines (84 loc) · 2.18 KB
/
exp2exp.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python
#######################################
#
# manipulate and process EXP files
#
# author:(c) Michael Aschauer <m AT ash.to>
# www: http:/m.ash.to
# licenced under: GPL v3
# see: http://www.gnu.org/licenses/gpl.html
#
#######################################
import stitchcode
import getopt
import sys
def usage():
print """
usage: exp2png.py [options] -i EXP-FILE -o EXP-FILE
applies conversions to EXP/Melco embroidery files.
options:
-h, --help print usage
-i, --input=FILE input EXP file
-o, --output=FILE output EXP file
-z, --zoom=FACTOR zoom in/out
-t, --to-triples convert to triple stitches
-r, --to-red-work convert to red work stitches
-d, --distance=VALUES distance of triple/redwork stitches in mm
"""
infile = "";
outfile = "";
zoom = 1
distance = 0.3
to_triple_stitches = False
to_red_work = False
def process_args():
global infile, outfile, zoom
global to_triple_stitches
global to_red_work
global distance
try:
opts, args = getopt.getopt(sys.argv[1:], "hi:o:z:trd:",
["help", "input=","output=","zoom=","to-triples","to-red-work",
"distance"])
except getopt.GetoptError, err:
# print help information and exit:
print str(err) # will print something like "option -a not recognized"
usage()
sys.exit(2)
for o, a in opts:
if o in ("-h", "--help"):
usage()
sys.exit()
elif o in ("-o", "--output"):
outfile = a
elif o in ("-i", "--input"):
infile = a
elif o in ("-z", "--zoom"):
zoom = float(a)
elif o in ("-t", "--to-triples"):
to_triple_stitches = True
elif o in ("-r", "--to-red_work"):
to_red_work = True
elif o in ("-d", "--distance"):
distance = float(a)
else:
usage();
sys.exit()
if len(infile) == 0:
print "options required."
usage()
sys.exit(2)
if __name__ == '__main__':
process_args()
if not outfile:
outfile = infile
emb = stitchcode.Embroidery()
emb.import_melco(infile)
emb.scale(zoom)
if to_triple_stitches:
print "convert to triple stitches"
emb.to_triple_stitches(distance*10)
if to_red_work:
print "convert to red work stitches"
emb.to_red_work(distance*10)
emb.save_as_exp(outfile)