mirror of
https://github.com/Ultimaker/Cura.git
synced 2025-07-06 22:47:29 -06:00
Fix finding layer numbers
That seems to have been unreliable. Luckily the original g-code is already broken up in layers, so searching it is completely unnecessary. Hopefully resolves issue #5630.
This commit is contained in:
parent
8ecf024334
commit
c9e7f3a245
1 changed files with 9 additions and 29 deletions
|
@ -1,9 +1,7 @@
|
||||||
# Copyright (c) 2019 Ultimaker B.V.
|
# Copyright (c) 2019 Ultimaker B.V.
|
||||||
# The PostProcessingPlugin is released under the terms of the AGPLv3 or higher.
|
# The PostProcessingPlugin is released under the terms of the AGPLv3 or higher.
|
||||||
|
|
||||||
from typing import Optional, Tuple
|
from typing import List
|
||||||
|
|
||||||
from UM.Logger import Logger
|
|
||||||
from ..Script import Script
|
from ..Script import Script
|
||||||
|
|
||||||
class FilamentChange(Script):
|
class FilamentChange(Script):
|
||||||
|
@ -65,9 +63,10 @@ class FilamentChange(Script):
|
||||||
}
|
}
|
||||||
}"""
|
}"""
|
||||||
|
|
||||||
def execute(self, data: list):
|
## Inserts the filament change g-code at specific layer numbers.
|
||||||
|
# \param data A list of layers of g-code.
|
||||||
"""data is a list. Each index contains a layer"""
|
# \return A similar list, with filament change commands inserted.
|
||||||
|
def execute(self, data: List[str]):
|
||||||
layer_nums = self.getSettingValueByKey("layer_number")
|
layer_nums = self.getSettingValueByKey("layer_number")
|
||||||
initial_retract = self.getSettingValueByKey("initial_retract")
|
initial_retract = self.getSettingValueByKey("initial_retract")
|
||||||
later_retract = self.getSettingValueByKey("later_retract")
|
later_retract = self.getSettingValueByKey("later_retract")
|
||||||
|
@ -88,32 +87,13 @@ class FilamentChange(Script):
|
||||||
if y_pos is not None:
|
if y_pos is not None:
|
||||||
color_change = color_change + (" Y%.2f" % y_pos)
|
color_change = color_change + (" Y%.2f" % y_pos)
|
||||||
|
|
||||||
color_change = color_change + " ; Generated by FilamentChange plugin"
|
color_change = color_change + " ; Generated by FilamentChange plugin\n"
|
||||||
|
|
||||||
layer_targets = layer_nums.split(",")
|
layer_targets = layer_nums.split(",")
|
||||||
if len(layer_targets) > 0:
|
if len(layer_targets) > 0:
|
||||||
for layer_num in layer_targets:
|
for layer_num in layer_targets:
|
||||||
layer_num = int(layer_num.strip())
|
layer_num = int(layer_num.strip()) + 1
|
||||||
if layer_num <= len(data):
|
if layer_num <= len(data):
|
||||||
index, layer_data = self._searchLayerData(data, layer_num - 1)
|
data[layer_num] = color_change + data[layer_num]
|
||||||
if layer_data is None:
|
|
||||||
Logger.log("e", "Could not find the layer {layer_num}".format(layer_num = layer_num))
|
|
||||||
continue
|
|
||||||
lines = layer_data.split("\n")
|
|
||||||
lines.insert(2, color_change)
|
|
||||||
final_line = "\n".join(lines)
|
|
||||||
data[index] = final_line
|
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
## This method returns the data corresponding with the indicated layer number, looking in the gcode for
|
|
||||||
# the occurrence of this layer number.
|
|
||||||
def _searchLayerData(self, data: list, layer_num: int) -> Tuple[int, Optional[str]]:
|
|
||||||
for index, layer_data in enumerate(data):
|
|
||||||
first_line = layer_data.split("\n")[0]
|
|
||||||
# The first line should contain the layer number at the beginning.
|
|
||||||
if first_line[:len(self._layer_keyword)] == self._layer_keyword:
|
|
||||||
# If found the layer that we are looking for, then return the data
|
|
||||||
if first_line[len(self._layer_keyword):] == str(layer_num):
|
|
||||||
return index, layer_data
|
|
||||||
return 0, None
|
|
Loading…
Add table
Add a link
Reference in a new issue