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
This commit is contained in:
c.lamboo 2023-10-12 21:09:10 +02:00
parent c3f3a86385
commit 14afd73c19

View file

@ -84,7 +84,7 @@ class GcodeStartEndFormatter(Formatter):
container_stack = ExtruderManager.getInstance().getExtruderStack(extruder_nr) container_stack = ExtruderManager.getInstance().getExtruderStack(extruder_nr)
setting_function = SettingFunction(expression) setting_function = SettingFunction(expression)
value = setting_function(container_stack) value = setting_function(container_stack, additional_variables=kwargs[str(extruder_nr)])
return value return value
@ -423,10 +423,17 @@ class StartSliceJob(Job):
:param value: A piece of g-code to replace tokens in. :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 :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: try:
# any setting can be used as a token # any setting can be used as a token
fmt = GcodeStartEndFormatter(default_extruder_nr = default_extruder_nr) 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: except:
Logger.logException("w", "Unable to do token replacement on start/end g-code") Logger.logException("w", "Unable to do token replacement on start/end g-code")
return str(value) return str(value)