Skip to content

Commit 1069b37

Browse files
committed
Count layers for all objects
1 parent f6ad66b commit 1069b37

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

KlipperPreprocessor.py

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,29 +114,53 @@ def execute(self, data):
114114
with TemporaryDirectory() as work_dir:
115115
Logger.log("d", "Initial run...")
116116

117+
total_layers = 0
118+
117119
filename = os.path.join(work_dir, "work.gcode")
118120
with open(filename, 'w') as work_file:
121+
first_layer_done = False
119122
for layer in data:
123+
if first_layer_done:
124+
work_file.write(";CURA_DATA_SPLIT_HERE\n")
125+
else:
126+
first_layer_done = True
120127
lines = layer.split("\n")
121128
for line in lines:
122-
work_file.write(line + "\n")
123129
if (line.startswith(';LAYER:')):
130+
total_layers += 1
124131
if add_timelapse_take_frame:
125132
work_file.write("TIMELAPSE_TAKE_FRAME\n")
126-
if add_set_print_stats_info:
127-
work_file.write("SET_PRINT_STATS_INFO CURRENT_LAYER=%i\n" % (int(line[7:]) + 1,))
128-
elif (line.startswith(';LAYER_COUNT:')):
129-
if add_set_print_stats_info:
130-
work_file.write("SET_PRINT_STATS_INFO TOTAL_LAYER=%s\n" % (line[13:],))
133+
work_file.write(line + "\n")
134+
135+
Logger.log("d", "Total layers found: %d", total_layers)
131136

132137
self.execute_preprocess_cancellation(filename)
133138

134139
self.execute_klipper_estimator(filename, work_dir)
135140

136141
Logger.log("d", "Return output...")
137142

143+
data = []
144+
current_layer = 0
138145
with open(filename) as work_file:
139-
return work_file.readlines()
146+
layer = []
147+
for line in work_file:
148+
line = line.strip()
149+
if line == ";CURA_DATA_SPLIT_HERE":
150+
data.append("\n".join(layer))
151+
layer = []
152+
else:
153+
layer.append(line)
154+
155+
if add_set_print_stats_info:
156+
if (line.startswith(';LAYER:')):
157+
current_layer += 1
158+
layer.append("SET_PRINT_STATS_INFO CURRENT_LAYER=%s" % (current_layer,))
159+
elif (line.startswith(';LAYER_COUNT:')):
160+
layer.append("SET_PRINT_STATS_INFO TOTAL_LAYER=%s" % (total_layers,))
161+
data.append("\n".join(layer))
162+
163+
return data
140164

141165
def execute_preprocess_cancellation(self, filename):
142166
if self.getSettingValueByKey("preprocess_cancellation_enabled"):

0 commit comments

Comments
 (0)