From 14afd73c19b369a97da6c39c1af2d3e58f1e3ac6 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Thu, 12 Oct 2023 21:09:10 +0200 Subject: [PATCH] Make sure default variables are available in start/end code The following properties are not settings-names, but could previously be used as template variables - material_id - time - date - day - initial_extruder_nr - material_id - material_name - material_type - material_brand - time - date - day - initial_extruder_nr These properties are _awkwardly_ propogated through the kwargs of the `get_value` method of `GcodeStartEndFormatter`. I don't quite like implementing it like this, but to avoid API breaks I couldn't change abusing the kwargs arg for this purpose. CURA-11155 --- plugins/CuraEngineBackend/StartSliceJob.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 06859aef556..4d9afd31bc0 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -84,7 +84,7 @@ def get_value(self, expression: str, args: str, kwargs: dict) -> str: container_stack = ExtruderManager.getInstance().getExtruderStack(extruder_nr) setting_function = SettingFunction(expression) - value = setting_function(container_stack) + value = setting_function(container_stack, additional_variables=kwargs[str(extruder_nr)]) return value @@ -423,10 +423,17 @@ def _expandGcodeTokens(self, value: str, default_extruder_nr: int = -1) -> str: :param value: A piece of g-code to replace tokens in. :param default_extruder_nr: Stack nr to use when no stack nr is specified, defaults to the global stack """ + if not self._all_extruders_settings: + self._cacheAllExtruderSettings() + try: # any setting can be used as a token fmt = GcodeStartEndFormatter(default_extruder_nr = default_extruder_nr) - return str(fmt.format(value)) + if self._all_extruders_settings is None: + return "" + settings = self._all_extruders_settings.copy() + settings["default_extruder_nr"] = default_extruder_nr + return str(fmt.format(value, **settings)) except: Logger.logException("w", "Unable to do token replacement on start/end g-code") return str(value)