Skip to content

Commit ca952c3

Browse files
committed
Rework first tool change handling
1 parent 5ffa0cb commit ca952c3

File tree

3 files changed

+19
-32
lines changed

3 files changed

+19
-32
lines changed

src/gcode_file.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,11 @@ def parse_print_settings(self):
7272

7373
is_tool_change = False
7474
for cmd, comment, index in self.layers[0].read_lines():
75-
7675
if comment and comment.strip() == b"START SCRIPT END":
7776
self.layers[0].start_gcode_end = index
7877
self.pr_index = index
7978
break
80-
79+
8180
for layer in self.layers:
8281
for cmd, comment, index in layer.read_lines():
8382
if comment and comment.strip() == b"TOOL CHANGE":
@@ -105,7 +104,21 @@ def parse_print_settings(self):
105104
else:
106105
self.log.warning("No pre-prime run")
107106
self.active_e = self.extruders[0]
108-
107+
108+
# find first tool change and remove it if it's before any print moves. No need to
109+
# do tool change here
110+
for cmd, comment, index in self.layers[0].read_lines():
111+
if not cmd or index <= self.layers[0].start_gcode_end:
112+
continue
113+
if gcode.is_tool_change(cmd) is not None:
114+
if self.settings.get_hw_config_value("prerun.prime") == "True" or gcode.last_match == 0:
115+
self.log.debug("Remove first tool change: {}".format(gcode.last_match))
116+
self.layers[0].delete_line(index)
117+
break
118+
elif gcode.is_extrusion_move(cmd) or gcode.is_extrusion_speed_move(cmd):
119+
# if print move before tool change, bail out. Tool change cannot be removed
120+
break
121+
109122
def open_file(self, gcode_file):
110123
""" Read given g-code file into list """
111124
self.gcode_file = gcode_file

src/slicer_prusa_slic3r.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -239,20 +239,7 @@ def parse_header(self):
239239

240240
def parse_print_settings(self):
241241
""" Slic3r specific settings """
242-
243242
super().parse_print_settings()
244-
if self.settings.get_hw_config_value("prerun.prime") == "True":
245-
return
246-
for cmd, comment, line_index in self.layers[0].read_lines():
247-
# find first tool change and remove it if it's T0. No need to
248-
# do tool change as e already have T0 active
249-
if not cmd:
250-
continue
251-
if line_index > self.layers[0].start_gcode_end and gcode.is_tool_change(cmd) is not None:
252-
if gcode.last_match == 0:
253-
self.log.debug("Remove first T0")
254-
self.layers[0].delete_line(line_index)
255-
break
256243

257244
def parse_layers(self, lines):
258245
"""
@@ -361,7 +348,7 @@ def filter_layers(self):
361348
layer_data[z]['slots'] = slots
362349

363350
self.max_slots = slots
364-
#print(self.max_slots)
351+
self.log.debug("Max slots: {}".format(self.max_slots))
365352

366353
# tag layers for actions: tool change, infill, etc
367354
zs.reverse()

src/slicer_simplify3d.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -296,24 +296,11 @@ def parse_layers(self, lines):
296296

297297
def parse_print_settings(self):
298298
"""
299-
Slic3r specific settings
299+
Simplify3D specific settings
300300
:return:
301301
"""
302302
super().parse_print_settings()
303303

304-
if self.settings.get_hw_config_value("prerun.prime") == "True":
305-
return
306-
for cmd, comment, line_index in self.layers[0].read_lines():
307-
# find first tool change and remove it if it's T0. No need to
308-
# do tool change as e already have T0 active
309-
if not cmd:
310-
continue
311-
if line_index > self.layers[0].start_gcode_end and gcode.is_tool_change(cmd) is not None:
312-
if gcode.last_match == 0:
313-
self.log.debug("Remove first T0")
314-
self.layers[0].delete_line(line_index)
315-
break
316-
317304
def check_layer_change(self, line, current_layer):
318305
"""
319306
Check if line is layer change
@@ -372,7 +359,7 @@ def filter_layers(self):
372359
layer_data[z]['slots'] = slots
373360

374361
self.max_slots = slots
375-
#print(self.max_slots)
362+
self.log.debug("Max slots: {}".format(self.max_slots))
376363

377364
# tag layers for actions: tool change, infill, etc
378365
zs.reverse()

0 commit comments

Comments
 (0)