From 51d64ad7f87946d90f78985c60039223514506e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janar=20S=C3=B6=C3=B6t?= Date: Wed, 26 Sep 2018 08:19:54 +0300 Subject: [PATCH] gcode_macro: macro improvement with parameters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Janar Sööt --- klippy/extras/gcode_macro.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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 # # 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