Auto Switching Pressure Advance Values Per Fillament


I recently wrote a macro that helps you set your pressure advance according to which filament you are using. All you have to do is put a m900 command in your start print gcode in your slicer, and it will work. M900 is used to set the linear advance value, which is the same thing as pressure advance. This macro takes the linear advance value, stores it as a float, and then uses that float to set your pressure advance value . Let me know if it works!

Ps: I set the PA value in my printer.cfg to be “.000” because in the case that I don’t have a PA value set for a specific filament, it will just revert back to the default. I prefer this over having a PA value that doesn’t work and messes up my print.

Start gcode:
M900 K.0000 (your PA value here)
blah blah blah (your start gcode)
blah blah blah (your start gcode)
blah blah blah (your start gcode)


[gcode_macro m900] 

    {% set PA = params.K|float %}


Why not just do this?

Start gcode:
SET_PRESSURE_ADVANCE ADVANCE=0.000 (your PA value here)
blah blah blah (your start gcode)
blah blah blah (your start gcode)
blah blah blah (your start gcode)


I thought that commands like that had to be stored in a macro, not run as a gcode, but if it works, then cool! I just didn’t think that that was possible lol.


Yep, that’s how those commands are designed to work. There are no extended gcode commands that have to be called from a macro.


I have a question this time. I want to be able to set the temperature automatically for any filament at the start of a print, for example, petg at 240, and pla at 220. But with this macro, I need to change those values every time I want to print with another filament. Can you help?

Here is my start print macro:

[gcode_macro START_PRINT]
    {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
	{% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(220)|float %}
    # Use absolute coordinates
    M104 S120 ; set temporary nozzle temp to prevent oozing during homing
    M140 S{BED_TEMP} ; set final bed temp
    # Start bed heating
    # Reset the G-Code Z offset (adjust Z offset if needed)
    # Home the printer
    #Restore Bed Mesh
    # Move the nozzle near the bed
    G1 Z5 F3000
    # Move Nozzle To Edge Of Bed
    G1 X2.0 Y8.0 F18000            ; go to edge of bed
    G1 Z0.2 F5000 
    # Move the nozzle very close to the bed and wait for print to start
    #Heat Bed and Nozzle
    M104 S{EXTRUDER_TEMP} ; set final nozzle temp
    M190 S{BED_TEMP} ; wait for bed temp to stabilize
    M109 S{EXTRUDER_TEMP} ; wait for nozzle temp to stabilize
    #Purge Line
    G1 X0.0 Y8.0 F18000   ; go to edge of bed
    G1 Z0.2 F5000   ; lower nozzle
    G92 E0.0   ; reset extruder position
    G1 Y100.0 E16.0 F1000.0  ; start intro line
    G92 E0.0   ; reset extruder position             
    G1 Y180.0 E18.0 F1000.0  ; finish thicker
    G92 E0.0   ; reset extruder position

Why not just have the slicer pass the correct print temp to the macro?

Or you pass the filament name to your START_PRINT macro and process this parameter.
For Cura this works with:

;Filament type = {material_type}
;Filament name = {material_name}

Some day I’ll extend my scripts to turn on my Nevermore fan and chamber filtering depending on used material.

Hi theophile,
I have a related question about setting pressure advance. When I setup my printer on klipper (recently) the printer.cfg file setup pressure advance like:

blah: blah
more stuff
pressure_advance = 0.07

This matches what is described in the klipper pressure advance instructions, but it does not follow with how other variables are set in printer.cfg. A bunch of other sites tell you to update the printer.cfg file using that formatting. I believe it should be:

blah: blah
more stuff
pressure_advance: 0.07

Is this correct, or does it matter if you use a “=” or “:”?

I would follow the instructions in the documentation.