forked from K-Tett/Klipper-FastSQV
-
Notifications
You must be signed in to change notification settings - Fork 4
/
FastSQV.py
89 lines (81 loc) · 3.09 KB
/
FastSQV.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
#!python
import sys
import re
import os
import time
# NOTE: Only works with ***SuperSlicer***
source_file=sys.argv[1]
# Read the ENTIRE g-code file into memory
with open(source_file, "r") as f:
lines = f.readlines() #count lines
# Process file to .gcode file for post-process script
if (source_file.endswith('.gcode')):
dest_file = re.sub('\.gcode$','',source_file)
try:
os.rename(source_file, dest_file+".sqv.bak")
except FileExistsError:
os.remove(dest_file+".sqv.bak")
os.rename(source_file, dest_file+".sqv.bak")
dest_file = re.sub('\.gcode$','',source_file)
dest_file = dest_file + '.gcode'
else:
dest_file = source_file
os.remove(source_file)
# Boolean variables
in_infill = False
in_internal_perimeter = False
in_solid_infill = False
in_top_solid_infill = False
in_internal_bridge = False
in_bridge_infill = False
# NOTE: External perimeters omitted since print quality is my main concern
# Open the destination file and write
with open(dest_file, "w") as of:
of.write('; Ensure macros are properly setup in klipper\n')
of.write('_USE_INFILL_SQV\n')
of.write('_USE_INTERNAL_PERIMETER_SQV\n')
of.write('_USE_SOLID_INFILL_SQV\n')
of.write('_USE_TOP_SOLID_INFILL_SQV\n')
of.write('_USE_INTERNAL_BRIDGE_SQV\n')
of.write('_USE_NORMAL_SQV\n')
for line_Index in range(len(lines)):
oline = lines[line_Index]
# print(oline)
# Parse gcode line
if oline.startswith(';TYPE:Internal infill'):
in_infill = True
of.write(oline)
of.write('_USE_INFILL_SQV\n')
elif oline.startswith(';TYPE:Internal perimeter'):
in_internal_perimeter = True
of.write(oline)
of.write('_USE_INTERNAL_PERIMETER_SQV\n')
elif oline.startswith(';TYPE:Solid infill'):
in_solid_infill = True
of.write(oline)
of.write('_USE_SOLID_INFILL_SQV\n')
elif oline.startswith(';TYPE:Top solid infill'):
in_top_solid_infill = True
of.write(oline)
of.write('_USE_TOP_SOLID_INFILL_SQV\n')
elif oline.startswith(';TYPE:Internal bridge infill'):
in_internal_bridge = True
of.write(oline)
of.write('_USE_INTERNAL_BRIDGE_SQV\n')
elif oline.startswith(';TYPE:Bridge infill'):
in_bridge_infill = True
of.write(oline)
of.write('_USE_BRIDGE_INFILL_SQV\n')
elif (oline.startswith(';TYPE:External perimeter') or oline.startswith('; INIT') or oline.startswith(';TYPE:Gap fill') or oline.startswith(';TYPE:Overhang perimeter') or oline.startswith(';TYPE:Thin wall')) and (in_infill or in_internal_perimeter or in_solid_infill or in_top_solid_infill or in_internal_bridge):
in_infill = False
in_internal_perimeter = False
in_solid_infill = False
in_top_solid_infill = False
in_internal_bridge = False
in_bridge_infill= False
of.write(oline)
of.write('_USE_NORMAL_SQV\n')
else:
of.write(oline)
of.close()
f.close()