Skip to content

Commit

Permalink
gcode_macro: Add "commandline" pseudo-variable
Browse files Browse the repository at this point in the history
Signed-off-by: Pedro Lamas <pedrolamas@gmail.com>
  • Loading branch information
pedrolamas committed Sep 27, 2021
1 parent 31ac9dc commit 8e40d42
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
15 changes: 15 additions & 0 deletions docs/Command_Templates.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,21 @@ gcode:
M140 S{bed_temp}
```

### The "commandline" variable

The full command line for the running macro can be access via the `commandline` pseudo-variable.

This is quite useful if you want to change the behavior of certain commands like the `M117`. For example:

```
[gcode_macro M117]
rename_existing: M117.1
gcode:
{% set message = commandline[5:] %}
M117.1 { message }
M118 { message }
```

### The "printer" Variable

It is possible to inspect (and alter) the current state of the printer
Expand Down
2 changes: 2 additions & 0 deletions klippy/extras/gcode_macro.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,11 +184,13 @@ def cmd(self, gcmd):
if self.in_script:
raise gcmd.error("Macro %s called recursively" % (self.alias,))
params = gcmd.get_command_parameters()
commandline = gcmd.get_commandline()
kwparams = dict(self.kwparams)
kwparams.update(params)
kwparams.update(self.variables)
kwparams.update(self.template.create_template_context())
kwparams['params'] = params
kwparams['commandline'] = commandline
self.in_script = True
try:
self.template.run_gcode_from_command(kwparams)
Expand Down

0 comments on commit 8e40d42

Please sign in to comment.