Skip to content

Commit

Permalink
Make sure default variables are available in start/end code
Browse files Browse the repository at this point in the history
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
  • Loading branch information
casperlamboo committed Oct 12, 2023
1 parent c3f3a86 commit 14afd73
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions plugins/CuraEngineBackend/StartSliceJob.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 14afd73

Please sign in to comment.