-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtweak-gcode-360.py
36 lines (26 loc) · 972 Bytes
/
tweak-gcode-360.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
import sys
COMMENT_PREFIX = ";"
def tweak_gcode(input: str, output: str):
line_count = 0
# Count lines
with open(input, "r") as input_file:
for line in input_file:
if not line.startswith(COMMENT_PREFIX):
line_count += 1
segment = int(line_count / 800)
line_count = 0
with open(input, "r") as input_file:
with open(output, "w") as output:
for line in input_file:
output.write(line)
if not line.startswith(COMMENT_PREFIX):
line_count += 1
if line_count == segment:
line_count = 0
output.write("@OCTOLAPSE TAKE-SNAPSHOT\n")
if __name__ == '__main__':
arguments = sys.argv
if len(arguments) != 3:
print("Usage: python tweak-gcode-360.py input_file.gcode output_file.gcode")
sys.exit(-1)
tweak_gcode(input=sys.argv[1], output=sys.argv[2])