Klipper and if statements – on a Voron 2.4, but not printer specific

Learned a few new things recently with Klipper and varying things like pressure advance based on variables that the slicer passes on. This is on my Voron 2.4r2-4473.

The Aussie Makerbogans discord helped out here by pointing out that Klipper is using Jinja2 – so while googling for Klipper help with if/then/else etc. didn’t turn up a lot of helpful things actually looking at the docs for Jinja did.

        #This section receives the variables sent to it by the slicer, see: https://ellis3dp.com/Print-Tuning-Guide/articles/passing_slicer_variables.html
    {% set bedtemp = params.BED|int %}
    {% set hotendtemp = params.HOTEND|int %}
    {% set chambertemp = params.CHAMBER|default(0)|int %}
    {% set FILAMENT_TYPE = params.FILAMENT|default('PLA')|string %}

#this sets the exhaust fan on and the nevermore off for PLA
    {% if FILAMENT_TYPE == "PLA" %}
    SET_FAN_SPEED FAN=Chamber_Exhaust_Fan SPEED=1.0
    SET_FAN_SPEED FAN=Nevermore SPEED=0
    SET_PRESSURE_ADVANCE EXTRUDER=extruder ADVANCE=0.0185
    M140 S60
    {% elif FILAMENT_TYPE == "FLEX" %}
    SET_FAN_SPEED FAN=Chamber_Exhaust_Fan SPEED=1.0
    SET_FAN_SPEED FAN=Nevermore SPEED=0
    SET_PRESSURE_ADVANCE EXTRUDER=extruder ADVANCE=0.03
    M140 S60
    {% elif FILAMENT_TYPE == "ABS" %}
    M140 S105
    SET_FAN_SPEED FAN=Chamber_Exhaust_Fan SPEED=0.1
    SET_FAN_SPEED FAN=Nevermore SPEED=0.3
    SET_PRESSURE_ADVANCE EXTRUDER=extruder ADVANCE=0.0185
    {% else %}
    SET_PRESSURE_ADVANCE EXTRUDER=extruder ADVANCE=0.04
    {% endif %}

Works a treat. If I end up using a 0.6 nozzle often that could be passed through as well to vary the PA automatically.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top