Python
Dynamic Macros's most powerful feature allows you to run Python code directly from within a macro.
Running Python from within a Macro
Disclaimer
This functionality allows Dynamic Macros to gain significant control over your printer and Klipper host. I am not responsible for whatever happens if you download a malicious macro.
There are three main reasons why this could be helpful:
- Allowing for deeper control of Klipper and the Klipper host
- A learning bridge for creating Klipper plugins/extras
- A tool to help develop Klipper plugins/extras without restarting Klipper
To run Python from within a Dynamic Macro, use either the python()
utility function, or the python_file()
utility function. The python()
function accepts python code as a multiline string, and the python_file()
function accepts a filename (relative to your printer.cfg
folder).
Tip
When using the python()
utiltiy function, Jinja2 (which converts the macro to GCode) may throw errors during parsing. If you are getting errors, it is recommended to switch to python_file()
.
Here are a few examples:
Python Math
macros.cfg | |
---|---|
Python File Running GCode
macros.cfg | |
---|---|
test.py | |
---|---|