I was asked about my gcode macros for loading and unloading so I’ll share them here. These macros should be easy to modify for other multi-extruder setups. These marcos would make more sense being named “parking/unparking” instead of “loading/unloading”, but I have not bothered to renamed them.
For context I am running four extruders to a 4-way Y-adapter in the Bowden tube. The single Bowden tube out of the adapter goes to a direct-feed extruder on top of a single hotend.
[gcode_macro LOAD_FILAMENT]
gcode:
{% set svv = printer.save_variables.variables %}
SAVE_GCODE_STATE NAME=LOAD_FILAMENT_state
{ action_respond_info("Loading T%s" % svv.active_tool) }
M83
G1 E100 F1200
G1 E100 F1200
G1 E100 F4000
G1 E100 F4000
G1 E100 F4000
G1 E90 F2000
G1 E10 F250
SAVE_VARIABLE VARIABLE=loaded_tool VALUE={ svv.active_tool }
{ action_respond_info("Loaded tool: %s" % svv.loaded_tool) }
RESTORE_GCODE_STATE NAME=LOAD_FILAMENT_state
[gcode_macro UNLOAD_FILAMENT]
gcode:
{% set svv = printer.save_variables.variables %}
SAVE_GCODE_STATE NAME=UNLOAD_FILAMENT_state
{ action_respond_info("Unloading T%s" % svv.active_tool) }
M83
G1 E-100 F2000
G1 E-100 F4000
G1 E-100 F4000
G1 E-100 F4000
G1 E-100 F4000
G1 E-100 F4000
SAVE_VARIABLE VARIABLE=loaded_tool VALUE=-1
{ action_respond_info("Loaded tool: %s" % svv.loaded_tool) }
RESTORE_GCODE_STATE NAME=UNLOAD_FILAMENT_state
The gist here is that we save the current gcode state first. With M83
(relative extruder coordinates), we retract or insert the filament however far we need to get from the nozzle to the park position, or vice versa, and then we restore the original gcode state. The macros end by setting the variable loaded_tool
to the number of whichever extruder is active (0 through 3) or to -1 when unloaded. I just noticed that since writing my shared_heater article I have renamed the currentExtruder
variable to active_tool
.
In my case the filament is parked 600 mm from the nozzle. The reason for multiple 100 mm extrude moves is because Klipper has a max_extrude_only_distance
which limits the length of any one extrude command. I could have raised that limit and used a single G1 E600
, but I played it safe and left the limit lower at 150 mm (which still feels like a lot).
I also change the movement speed in the G1 calls. Unloading starts at F2000 to get out of the nozzle, then speeds up to F4000 when the tip is in the tube. Loading goes at F1200 until the tip gets through the 4-way adapter, speeds up to F4000 until it’s close to the nozzle, then slows down to F2000 and then F250 at the hotend.
That’s about it — they are pretty simple macros. Until next time, happy printing!
When running these macros to test them I get the error “Unable to parse ‘T1’ as a literal”, perhaps a Klipper update has broken something here? Thanks!
I think the fix in the LOAD_FILAMENT block is to change the line to this:
SAVE_VARIABLE VARIABLE=loaded_tool VALUE=”‘{ svv.active_tool }'”