gcode_macro: macro improvement with parameters
Signed-off-by: Janar Sööt <janar.soot@gmail.com>
This commit is contained in:
parent
170b9678fb
commit
51d64ad7f8
|
@ -3,6 +3,7 @@
|
||||||
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
# Copyright (C) 2018 Kevin O'Connor <kevin@koconnor.net>
|
||||||
#
|
#
|
||||||
# This file may be distributed under the terms of the GNU GPLv3 license.
|
# This file may be distributed under the terms of the GNU GPLv3 license.
|
||||||
|
import logging
|
||||||
|
|
||||||
class GCodeMacro:
|
class GCodeMacro:
|
||||||
def __init__(self, config):
|
def __init__(self, config):
|
||||||
|
@ -19,9 +20,16 @@ class GCodeMacro:
|
||||||
def cmd(self, params):
|
def cmd(self, params):
|
||||||
if self.in_script:
|
if self.in_script:
|
||||||
raise self.gcode.error("Macro %s called recursively" % (self.alias,))
|
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
|
self.in_script = True
|
||||||
try:
|
try:
|
||||||
self.gcode.run_script_from_command(self.script)
|
self.gcode.run_script_from_command(script)
|
||||||
finally:
|
finally:
|
||||||
self.in_script = False
|
self.in_script = False
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue