From 39652185011d9b3f171ff88bf86336f9167be3b6 Mon Sep 17 00:00:00 2001 From: Lipu Fei Date: Mon, 8 Oct 2018 14:40:38 +0200 Subject: [PATCH] Fix value templating for gcode CURA-5793 Fix GcodeStartEndFormatter to take the correct default_extruder_nr instead of always using -1. --- plugins/CuraEngineBackend/StartSliceJob.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 28e442033b..bb9387a65d 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -41,11 +41,15 @@ class StartJobResult(IntEnum): ## Formatter class that handles token expansion in start/end gcode class GcodeStartEndFormatter(Formatter): - def get_value(self, key: str, args: str, kwargs: dict, default_extruder_nr: str = "-1") -> str: #type: ignore # [CodeStyle: get_value is an overridden function from the Formatter class] + def __init__(self, default_extruder_nr: int = -1) -> None: + super().__init__() + self._default_extruder_nr = default_extruder_nr + + def get_value(self, key: str, args: str, kwargs: dict) -> str: #type: ignore # [CodeStyle: get_value is an overridden function from the Formatter class] # The kwargs dictionary contains a dictionary for each stack (with a string of the extruder_nr as their key), # and a default_extruder_nr to use when no extruder_nr is specified - extruder_nr = int(default_extruder_nr) + extruder_nr = self._default_extruder_nr key_fragments = [fragment.strip() for fragment in key.split(",")] if len(key_fragments) == 2: @@ -339,7 +343,7 @@ class StartSliceJob(Job): try: # any setting can be used as a token - fmt = GcodeStartEndFormatter() + fmt = GcodeStartEndFormatter(default_extruder_nr = default_extruder_nr) settings = self._all_extruders_settings.copy() settings["default_extruder_nr"] = default_extruder_nr return str(fmt.format(value, **settings))