-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCetus-post-script.py
46 lines (42 loc) · 1.39 KB
/
Cetus-post-script.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
import sys
import re
import tempfile
import os
print("""
+++++++++++++++++++++++++++++++++++++++++++++++++++++
+++ Adjusting extrusion lengths for Cetus printer +++
+++++++++++++++++++++++++++++++++++++++++++++++++++++
""")
try:
file = sys.argv[1]
E = re.compile(r" E([-0-9.]+)")
F = re.compile(r" F([-0-9.]+)")
out = ""
with open(file, 'r') as f:
for line in f:
match = E.search(line)
if match:
# Scale extrusion
try:
new_E = float(match.group(1)) * 23.
line = re.sub(E, " E%f"%(new_E), line)
except ValueError:
# Probably matched something that is not an E command
pass
match = F.search(line)
if match and 'X' not in line and 'Y' not in line and 'Z' not in line:
# Scale speed if there is no actual axis movement
try:
new_F = float(match.group(1)) * 23.
line = re.sub(F, " F%f"%(new_F), line)
except ValueError:
# Probably matched something that is not an E command
pass
out += line
except Exception as e:
print("Script failed!")
print(e)
input()
else:
with open(file, 'w') as f:
f.write(out)