From 036516b8f9d18a94d20c0e366a9bf7b4d049f023 Mon Sep 17 00:00:00 2001 From: "c.lamboo" Date: Thu, 16 Nov 2023 13:53:43 +0100 Subject: [PATCH] Re-add support for post slice data variables in start/end gcode With previous implementation we lost support for these variables in start/end gcode "filament_cost", "print_time", "filament_amount", "filament_weight", "jobname" CURA-11347 --- plugins/CuraEngineBackend/StartSliceJob.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/plugins/CuraEngineBackend/StartSliceJob.py b/plugins/CuraEngineBackend/StartSliceJob.py index 2887743b4f..37a2116f5d 100644 --- a/plugins/CuraEngineBackend/StartSliceJob.py +++ b/plugins/CuraEngineBackend/StartSliceJob.py @@ -69,6 +69,14 @@ class GcodeStartEndFormatter(Formatter): self._additional_per_extruder_settings: Optional[Dict[str, Dict[str, any]]] = additional_per_extruder_settings def get_value(self, expression: str, args: [str], kwargs: dict) -> str: + + # The following variables are not settings, but only become available after slicing. + # when these variables are encountered, we return them as-is. They are replaced later + # when the actual values are known. + post_slice_data_variables = ["filament_cost", "print_time", "filament_amount", "filament_weight", "jobname"] + if expression in post_slice_data_variables: + return f"{{{expression}}}" + extruder_nr = self._default_extruder_nr # The settings may specify a specific extruder to use. This is done by @@ -102,6 +110,9 @@ class GcodeStartEndFormatter(Formatter): setting_function = SettingFunction(expression) value = setting_function(container_stack, additional_variables=additional_variables) + print("value", value) + print("expression", expression) + return value