-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdst-step-counter.py
56 lines (44 loc) · 1.43 KB
/
dst-step-counter.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
import pyembroidery
import sys
# at least one input element is required
if len(sys.argv) != 2:
print("usage: dst-step-counter address_of_the_dst_file.dst")
exit()
# decoding the dst file
emb_pattern = pyembroidery.read_dst(sys.argv[1])
print("name: " + emb_pattern.extras["name"])
print("Stich Count: " + emb_pattern.extras["ST"])
print("Color: " + emb_pattern.extras["CO"])
print("+X: " + emb_pattern.extras["+X"])
print("-X: " + emb_pattern.extras["-X"])
print("+Y: " + emb_pattern.extras["+Y"])
print("-Y: " + emb_pattern.extras["-Y"])
stepx_sum = 0
stepy_sum = 0
dirx_sum = 0
diry_sum = 0
for i in range(0, emb_pattern.count_stitches()):
stepx_sum += abs(emb_pattern.stitches[i][0])
stepy_sum += abs(emb_pattern.stitches[i][1])
if i != 0:
current_st = emb_pattern.stitches[i][0]
past_st = emb_pattern.stitches[i - 1][0]
if current_st == 0:
current_st = 1
if past_st == 0:
past_st = 1
if (current_st * past_st) < 0:
dirx_sum += 1
current_st = emb_pattern.stitches[i][1]
past_st = emb_pattern.stitches[i - 1][1]
if current_st == 0:
current_st = 1
if past_st == 0:
past_st = 1
if (current_st * past_st) < 0:
diry_sum += 1
print("=================")
print("sum_x: " + str(stepx_sum))
print("sum_y: " + str(stepy_sum))
print("dir_x: " + str(dirx_sum))
print("dir_y: " + str(diry_sum))