gcode_macro: macro improvement with parameters

Signed-off-by: Janar Sööt <janar.soot@gmail.com>
This commit is contained in:
Janar Sööt 2018-09-26 08:19:54 +03:00 committed by KevinOConnor
parent 170b9678fb
commit 51d64ad7f8
1 changed files with 9 additions and 1 deletions

View File

@ -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