/
FastGyroidInfill.py
48 lines (42 loc) · 1.25 KB
/
FastGyroidInfill.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
#!python
import sys
import re
import os
import time
sourceFile=sys.argv[1]
# Read the ENTIRE g-code file into memory
with open(sourceFile, "r") as f:
lines = f.readlines()
if (sourceFile.endswith('.gcode')):
destFile = re.sub('\.gcode$','',sourceFile)
try:
os.rename(sourceFile, destFile+".sqv.bak")
except FileExistsError:
os.remove(destFile+".sqv.bak")
os.rename(sourceFile, destFile+".sqv.bak")
destFile = re.sub('\.gcode$','',sourceFile)
destFile = destFile + '.gcode'
else:
destFile = sourceFile
os.remove(sourceFile)
inInfill = False
with open(destFile, "w") as of:
of.write('; Ensure macros are properly setup in klipper\n')
of.write('_USE_INFILL_SQV\n')
of.write('_USE_NORMAL_SQV\n')
for lIndex in range(len(lines)):
oline = lines[lIndex]
# print(oline)
# Parse gcode line
if oline.startswith(';TYPE:Internal infill'):
inInfill = True
of.write(oline)
of.write('_USE_INFILL_SQV\n')
elif (oline.startswith(';TYPE:') or oline.startswith('; INIT')) and inInfill:
inInfill = False
of.write(oline)
of.write('_USE_NORMAL_SQV\n')
else:
of.write(oline)
of.close()
f.close()