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
This commit is contained in:
c.lamboo 2023-11-16 13:53:43 +01:00
parent 08f46fcff0
commit 036516b8f9

View file

@ -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