Flexible Interpreted Macros
This project was created as an experiment. What could happen if Klipper macros were fully interpreted, not rendered? This is not intended as a finished product for your printer (at least not yet). The thinking behind interpreted macros is that they can receive updates mid-run, do more complex logic, and allow for faster testing of macros or parts of Klippy extras.
More info on macro rendering and variable updates
Run the following commands in SSH:
cd ~
git clone https://github.com/3DCoded/iMacros
cd iMacros
ln -f imacro.py ~/klipper/klippy/extras/imacro.py
sudo service klipper restart
iMacros can be defined with the following configuration options:
[imacro name]
#script:
# A Python script using the special functions listed below.
#path:
# The path to a Python script on the local filesystem. Either this
# parameter or "script" must be provided.
#absolute_path: False
# Ignored if "script" is set. If this is set to True, the path will
# reference an absolute path. If set to false, the path will be
# relative to the printer configuration folder.
#description: iMacro
# This will add a short description used at the HTLP command or while
# using the auto completion feature. Default "iMacro"
To run an iMacro, simply use the command that's the name of your macro.
You can update file-based iMacros without restarting Klipper. However, iMacros directly declared within the printer configuration cannot be updated without restarting Klipper. This makes file-based iMacros more suitable for the majority of use-cases.
iMacros includes extra Python utilities to make writing iMacros simpler and more powerful.
printerThis is just like theprinterobject in a standardgcode_macro. For example, you can useprinter.toolhead.homed_axesto get a string of the currently homed axes.paramsThis is just like theparamsobject in a standardgcode_macro. For example, you can useparams.NAMEto get the value of the parameter calledNAME. If the parameter does not exist,Noneis returned.rawparamsThis is just like therawparamsobject in a standardgcode_macro. This is a string representing all the parameters passed to the macro.cmdUnique to iMacros. This allows for executing G-code commands with a custom syntax. For example,cmd.G1(x=100)runsG1 X100. A combination of positional and keyword arguments can be passed. For example,cmd.G1('X100', 'Y150', F=6000)will runG1 X100 Y150 F6000.respondPrints information in the printer console. By default, this is HTML-escaped, but to disable the escaping,unsafe=Truecan be passed to the function.