diff options
author | Janar Sööt <janar.soot@gmail.com> | 2018-09-26 08:19:54 +0300 |
---|---|---|
committer | KevinOConnor <kevin@koconnor.net> | 2018-09-26 08:03:39 -0400 |
commit | 51d64ad7f87946d90f78985c60039223514506e5 (patch) | |
tree | 3d35527a4176ebbaf2116c8eec49be301f4aa8a5 /klippy/extras/gcode_macro.py | |
parent | 170b9678fba2749063023008f51ebdff7e0e0759 (diff) | |
download | kutter-51d64ad7f87946d90f78985c60039223514506e5.tar.gz kutter-51d64ad7f87946d90f78985c60039223514506e5.tar.xz kutter-51d64ad7f87946d90f78985c60039223514506e5.zip |
gcode_macro: macro improvement with parameters
Signed-off-by: Janar Sööt <janar.soot@gmail.com>
Diffstat (limited to 'klippy/extras/gcode_macro.py')
-rw-r--r-- | klippy/extras/gcode_macro.py | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/klippy/extras/gcode_macro.py b/klippy/extras/gcode_macro.py index 6d85f39f..6ee243c8 100644 --- a/klippy/extras/gcode_macro.py +++ b/klippy/extras/gcode_macro.py @@ -3,6 +3,7 @@ # Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net> # # This file may be distributed under the terms of the GNU GPLv3 license. +import logging class GCodeMacro: def __init__(self, config): @@ -19,9 +20,16 @@ class GCodeMacro: def cmd(self, params): if self.in_script: raise self.gcode.error("Macro %s called recursively" % (self.alias,)) + script = "" + try: + script = self.script.format(**params) + except Exception: + msg = "Macro %s script formatting failed" % (self.alias,) + logging.exception(msg) + raise self.gcode.error(msg) self.in_script = True try: - self.gcode.run_script_from_command(self.script) + self.gcode.run_script_from_command(script) finally: self.in_script = False |