Skip to content

Instantly share code, notes, and snippets.

@bistory
Created February 11, 2023 21:06
Show Gist options
  • Select an option

  • Save bistory/629b596c5c49d6b01f5cf06ea2f2690f to your computer and use it in GitHub Desktop.

Select an option

Save bistory/629b596c5c49d6b01f5cf06ea2f2690f to your computer and use it in GitHub Desktop.
Macros for loading and unloading filament with Klipper
[gcode_macro LOAD_FILAMENT]
gcode:
{% set speed = params.SPEED|default(300) %}
{% set max_velocity = printer.configfile.settings['extruder'].max_extrude_only_velocity %}
SAVE_GCODE_STATE NAME=load_state
M300 # beep
G91
G92 E0
G1 E350 F{max_velocity} # fast-load
G1 E25 F{speed} # purge
M300
M300
RESTORE_GCODE_STATE NAME=load_state
[gcode_macro UNLOAD_FILAMENT]
gcode:
{% set speed = params.SPEED|default(300) %}
{% set max_velocity = printer.configfile.settings['extruder'].max_extrude_only_velocity %}
SAVE_GCODE_STATE NAME=unload_state
G91
M300 # beep
G92 E0
G1 E25 F{speed} # purge
G1 E-420 F{max_velocity} # fast-unload
M300
M300
RESTORE_GCODE_STATE NAME=unload_state
@eboston
Copy link

eboston commented Jan 31, 2025

I have hated this change ever since it was implemented because I cannot get it to work. I create these macros and when I try using them from the extrude menu, I get a temperature too low error. I put messages in the macros to see if they get called, but never see the message. Is there something I am missing? The macros I have will heat the extruder.

@mactep
Copy link

mactep commented Nov 20, 2025

There is an issue with the heating macro as it does not wait for the filament to be extruded before turning off the heater. To fix this we need to insert an M400 before the M104 S0. It is not really necessary for the unload macro, since it quickly pulls the filament off the nozzle, but for the load one it may get the nozzle to be too cold for properly extrude the new filament.

{% if turn_off_extruder %}
        M400
        M104 S0 ; Turn off extruder heater
{% endif %}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment