Klipper: [Feature Request] Conditional macros

Created on 6 May 2019  路  7Comments  路  Source: KevinOConnor/klipper

Hello.
I am looking for a way to bring some logic into my macro's:
Example:
print_start filament=PLA

[gcode_macro print_start]
if filament == PLA
    macro_PLA
if filament == ABS
    macro_ABS
else
    macro_youaredoomed

Maybe I am not the only one and this could be considered as a future feature.

Thanks.
M

Most helpful comment

Actually, I'll tell you a little secret.
You can use the Jinja2 templating engine in gcode_macros gcode.
The latest code in the master branch has it built in.
http://jinja.pocoo.org/docs/2.10/templates/

[gcode_macro print_start]
default_parameter_FILAMENT: PLA
gcode:
    {% if FILAMENT == 'PLA' %}
        macro_PLA
    {% elif FILAMENT == 'ABS' %}
        macro_ABS
    {% else %}
        macro_youaredoomed
    {% endif %}

This example is not tested in working klipper.
Edited: default parameter has to be in capital letters

All 7 comments

Hi @tameike000,

It did not look like there was a Klipper log file attached to this ticket. The log file has been engineered to answer common questions the Klipper developers have about the software and its environment (software version, hardware type, configuration, event timing, and hundreds of other questions).

Unfortunately, too many people have opened tickets without providing the log. That consumes developer time; time that would be better spent enhancing the software. If this ticket references an event that has occurred while running the software then the Klipper log must be attached to this ticket. Otherwise, this ticket will be automatically closed in a few days.

For information on obtaining the Klipper log file see: https://github.com/KevinOConnor/klipper/blob/master/docs/Contact.md

The log can still be attached to this ticket - just add a comment and attach the log to that comment.

Best regards,
~ Your friendly GitIssueBot

PS: I'm just an automated script, not a human being.

you know that you can have parameters in macros, that can be changed when you send the command.

If I want the toolhead to park in an other spot than the normal one I send

PARK_MACRO Y=85 Z=50

[gcode_macro PARK_MACRO]
default_parameter_X: 0
default_parameter_Y: -85
default_parameter_Z: 30
gcode:
M117 PARKING..
G91
G1 E-3.14 F1500
G1 Z{Z}
G90
G1 X{X} Y{Y} F3000

@Hywelmartin
Thanks so much for that example! I think I did not fully understand the potential of the existing implemention yet.

Actually, I'll tell you a little secret.
You can use the Jinja2 templating engine in gcode_macros gcode.
The latest code in the master branch has it built in.
http://jinja.pocoo.org/docs/2.10/templates/

[gcode_macro print_start]
default_parameter_FILAMENT: PLA
gcode:
    {% if FILAMENT == 'PLA' %}
        macro_PLA
    {% elif FILAMENT == 'ABS' %}
        macro_ABS
    {% else %}
        macro_youaredoomed
    {% endif %}

This example is not tested in working klipper.
Edited: default parameter has to be in capital letters

@mcmatrix if that works I'll send 1001 brownie points over.
Thanks for the hint. I will dig into that.

I'm going to close this ticket as it looks like the conversation has concluded. As indicated, conditional macros are supported (though documentation is still in progress).

-Kevin

@mcmatrix will the following work?
[gcode_macro park]
default_parameter_tool:0
gcode:
{% if TOOL== 0 %}
G1 X-12 F6000
{% else %}
G1 X475 F6000
{% endif %}

or do I need elif in order to make it work?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

talfari picture talfari  路  5Comments

aegelsky picture aegelsky  路  3Comments

amaximchuk picture amaximchuk  路  6Comments

ChiliApple picture ChiliApple  路  4Comments

LazaroFilm picture LazaroFilm  路  6Comments