# macros.cfg
############################################################################ ########################## ProForge 5 Macros ############################# ############################################################################
#config file version v1.2.0 #release date: 03.06.2026
[gcode_macro _END_PRINT] gcode: # Lower build plate {% set current_z = printer.toolhead.position.z %} {% set max_z = printer.toolhead.axis_maximum.z %} {% set z_lower = 20 %} {% set new_z = current_z + z_lower %} M400 ; Wait for all moves to finish G90 ; Absolute positioning {% if new_z <= max_z - 5 %} G91 ; Relative positioning G1 Z{z_lower} F600 ; Lower bed 20mm (raise nozzle) G90 ; Back to absolute positioning {% else %} G1 Z{max_z - 5} F600 ; Move to Z max height -5 {% endif %}
# Assume toolchanger flow is OK unless proven otherwise SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1
G28 X Y
# Dock active print head if carriage says one is mounted {% if printer["gcode_button carriage_tool_sensor"].state == "PRESSED" %} DOCK {% endif %}
# Turn off heaters and fans M140 S0 M104 S0 T0 M104 S0 T1 M104 S0 T2 M104 S0 T3 M104 S0 T4 M106 S0
CHAMBER_OFF
# Only do final park + motor disable if docking succeeded {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} G1 X500 Y400 F16000 # Disable steppers M84 {% else %} { action_respond_info("end print safe shutdown completed, but tool docking was not confirmed") } M117 check tool dock {% endif %}
BED_MESH_CLEAR UPDATE_DELAYED_GCODE ID=FILTER_FAN_OFF DURATION=300 SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=-1 G90
[gcode_macro CANCEL_PRINT] description: Cancel the actual running print rename_existing: CANCEL_PRINT_BASE gcode: CLEAR_PAUSE _END_PRINT CANCEL_PRINT_BASE UPDATE_DELAYED_GCODE ID=FILTER_FAN_OFF DURATION=300 G90
[gcode_macro PAUSE] description: Pause the actual running print rename_existing: PAUSE_BASE gcode: PAUSE_BASE # Lower build plate {% set current_z = printer.toolhead.position.z %} {% set max_z = printer.toolhead.axis_maximum.z %} {% set z_lower = 30 %} {% set new_z = current_z + z_lower %} M400 ; Wait for all moves to finish G90 ; Absolute positioning {% if new_z <= max_z - 5 %} G91 ; Relative positioning G1 Z{z_lower} F600 ; Lower bed 20mm (raise nozzle) G90 ; Back to absolute positioning {% else %} G1 Z{max_z - 5} F600 ; Move to Z max height -5 {% endif %} FRONT SET_IDLE_TIMEOUT TIMEOUT=86400 #one day in seconds {% set active_extruder = printer.toolhead.extruder %} {% set current_temp = printer[active_extruder].temperature %} {% if active_extruder == "extruder" %} {% set tool_index = 0 %} {% else %} {% set tool_index = active_extruder[-1]|int %} {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_temp VALUE={current_temp} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extrud
{% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_temp VALUE={current_temp} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE={tool_index} SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE={tool_index} {% if tool_index == 0 %} SET_GCODE_VARIABLE MACRO=_filament_load_0 VARIABLE=user_temp VALUE={current_temp} {% elif tool_index == 1 %} SET_GCODE_VARIABLE MACRO=_filament_load_1 VARIABLE=user_temp VALUE={current_temp} {% elif tool_index == 2 %} SET_GCODE_VARIABLE MACRO=_filament_load_2 VARIABLE=user_temp VALUE={current_temp} {% elif tool_index == 3 %} SET_GCODE_VARIABLE MACRO=_filament_load_3 VARIABLE=user_temp VALUE={current_temp} {% elif tool_index == 4 %} SET_GCODE_VARIABLE MACRO=_filament_load_4 VARIABLE=user_temp VALUE={current_temp} {% endif %} M118 Pausing... Saved temperature of tool T{tool_index}: {current_temp}°C
[gcode_macro RESUME] description: Resume the actual running print rename_existing: RESUME_BASE variable_extruder_restore_temp: 0 variable_extruder_restore_tool: -1 # -1 means no tool was saved gcode: {% if extruder_restore_tool >= 0 %} {% if extruder_restore_temp > 0 %} M118 Resuming... Restoring temp {extruder_restore_temp}°C to tool T{extruder_restore_tool} M109 S{extruder_restore_temp} T{extruder_restore_tool} M118 Resuming... Restored temp {extruder_restore_temp}°C to tool T{extruder_restore_tool} {% else %} M118 Resuming... Tool T{extruder_restore_tool} had no saved temperature. {% endif %} _RESUME_WIPE {% else %} M118 Resuming... No tool was previously active. Skipping wipe and temperature restore. {% endif %} RESUME_BASE SET_IDLE_TIMEOUT TIMEOUT=600
[gcode_macro _RESUME_WIPE] description: Wipe the nozzle after resuming on pause variable_extruder_restore_tool: -1 gcode: {% set tool = extruder_restore_tool %} {% set svv = printer.save_variables.variables %} G90 {% if tool == 0 %} G0 Y{svv.zero_dock_y} F20000 G0 X{svv.zero_dock_x + 35} F20000 G0 X{svv.zero_dock_x + 7} F9000 {% elif tool == 1 %} G0 Y{svv.one_dock_y} F20000 G0 X{svv.one_dock_x + 35} F20000 G0 X{svv.one_dock_x + 7} F9000 {% elif tool == 2 %} G0 Y{svv.two_dock_y} F20000 G0 X{svv.two_dock_x + 35} F20000 G0 X{svv.two_dock_x + 7} F9000 {% elif tool == 3 %} G0 Y{svv.three_dock_y} F20000 G0 X{svv.three_dock_x + 35} F20000 G0 X{svv.three_dock_x + 7} F9000 {% elif tool == 4 %} G0 Y{svv.four_dock_y} F20000 G0 X{svv.four_dock_x + 35} F20000 G0 X{svv.four_dock_x + 7} F9000 {% else %} M118 Invalid tool index for RESUME_WIPE {% endif %} G92 E0 G0 E10 F600 #Prime the nozzle G92 E0 G0 E-0.5 F1500 G92 E0 _WIPE G0 X0 F20000
[gcode_macro _CHOME] description: Homes XYZ axis only if printer is in a non-homed state gcode: {% if "xyz" not in printer.toolhead.homed_axes %} G28 {% endif %}
[gcode_macro _CHOME_TOOL] description: Homes XY axis only if XY is in a non-homed state gcode: {% if "xy" not in printer.toolhead.homed_axes %} G28 X Y {% endif %}
[gcode_macro CENTER] description: Moves the toolhead to the center gcode: _CHOME_TOOL G90 G1 X250 Y200 F9000
[gcode_macro FRONT] description: Moves the toolhead to the front gcode: _CHOME_TOOL G90 G1 X250 Y10 F9000
[gcode_macro UNLOAD_FILAMENT] description: Unload filament from the currently selected tool head gcode: {% set extruder = printer.toolhead.extruder %} {% if extruder == "extruder" %} {% set tool_head = 0 %} {% elif extruder == "extruder1" %} {% set tool_head = 1 %} {% elif extruder == "extruder2" %} {% set tool_head = 2 %} {% elif extruder == "extruder3" %} {% set tool_head = 3 %} {% elif extruder == "extruder4" %} {% set tool_head = 4 %} {% else %} {% set tool_head = 0 %} {% endif %}
M117 Unloading filament from Tool{tool_head} SET_LED LED=SO3RGB_{tool_head} RED=0.0 GREEN=0.5 BLUE=0.5 _filament_unload_init_{tool_head}
[delayed_gcode FILTER_FAN_OFF] gcode: SET_FAN_SPEED FAN=filter_fan SPEED=0
######################################## # Tool Changing Macros ########################################
[gcode_macro CAM_POSITION] description: Set the servo cam angle gcode: {% set serv_angle=params.A|default(0)|float %} SET_SERVO SERVO=toolchanger ANGLE={ serv_angle } # Move servo arm G4 P1100 # Allow time to make move
[gcode_macro T0] gcode: ACTIVATE_EXTRUDER EXTRUDER=extruder
[gcode_macro T1] gcode: ACTIVATE_EXTRUDER EXTRUDER=extruder1
[gcode_macro T2] gcode: ACTIVATE_EXTRUDER EXTRUDER=extruder2
[gcode_macro T3] gcode: ACTIVATE_EXTRUDER EXTRUDER=extruder3
[gcode_macro T4] gcode: ACTIVATE_EXTRUDER EXTRUDER=extruder4
[gcode_macro _OFFSET_RESET] description: Reset any offsets. gcode: SET_GCODE_OFFSET X=0 SET_GCODE_OFFSET Y=0 SET_GCODE_OFFSET Z=0
[gcode_macro _SERVO_DOCK] gcode: SET_SERVO SERVO=toolchanger ANGLE=28 # Set cam release angle G4 P1100 # Allow time to make move
[gcode_macro _SERVO_SELECT] gcode: SET_SERVO SERVO=toolchanger ANGLE=110 # Set cam locking angle G4 P1100 # Allow time to make move
[gcode_macro _WIPE] gcode: {% if printer[printer.toolhead.extruder].temperature >= 165 %} G92 E0 G0 E-0.5 F5000 G92 E0 {% endif %} G91 G1 X+12 F3500 G1 X-12 F3500 G1 X+12 F3500 G1 X-12 F3500 G90
[gcode_macro _RETRACT] gcode: {% if printer[printer.toolhead.extruder].temperature >= 170 %} G92 E0 G0 E-6 F6000 G92 E0 {% endif %}
[gcode_macro _PRIME] gcode: {% if printer[printer.toolhead.extruder].temperature >= 165 %} G92 E0 G0 E3 F3000 G92 E0 {% endif %}
[gcode_macro _ZHOP] gcode: {% if printer.virtual_sdcard.is_active %} G91 G1 Z1 F2000 G90 {% endif %}
# Each SELECT_PHx outer macro only runs the pre-check and then hands off to its # inner _SELECT_PHx macro. The inner macro's Jinja2 is rendered when IT # runs (after _PRE_SELECT_CHECK has finished), so it reads the fresh values of # can_continue and already_selected instead of the stale pre-call values.
[gcode_macro SELECT_PH1] gcode: _PRE_SELECT_CHECK TOOL=0 _SELECT_PH1
[gcode_macro _SELECT_PH1] gcode: {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 and printer["gcode_macro _toolchanger_state"].already_selected|int == 0 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder G90 G0 Y{svv.zero_select_y} F20000 G0 X{svv.zero_select_x + 50} F20000 G0 X{svv.zero_select_x + 7} F10000 G0 X{svv.zero_select_x} F3000 G0 Y{svv.zero_dock_y} F3000 _SERVO_SELECT G0 X{svv.zero_select_x + 8} F12000 _PRIME #_WIPE G0 X0 F12000 {% if "xyz" in printer.toolhead.homed_axes %} SET_GCODE_OFFSET X=0 SET_GCODE_OFFSET Y=0 SET_GCODE_OFFSET Z=0 {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=0 SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE=0 _POST_SELECT_CHECK TOOL=0 {% endif %}
[gcode_macro _DOCK_PH1] gcode: _CHOME_TOOL {% set svv = printer.save_variables.variables %} _RETRACT _ZHOP _OFFSET_RESET G90 G0 Y{svv.zero_dock_y} F20000 G0 X{svv.zero_dock_x + 31} F20000 G0 X{svv.zero_dock_x} F2000 _SERVO_DOCK G0 Y{svv.zero_select_y} F4000 G0 X{svv.zero_dock_x + 10} F12000 G0 X15 F20000
[gcode_macro SELECT_PH2] gcode: _PRE_SELECT_CHECK TOOL=1 _SELECT_PH2
[gcode_macro _SELECT_PH2] gcode: {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 and printer["gcode_macro _toolchanger_state"].already_selected|int == 0 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder1 G90 G0 Y{svv.one_select_y} F20000 G0 X{svv.one_select_x + 50} F20000 G0 X{svv.one_select_x + 7} F10000 G0 X{svv.one_select_x} F3000 G0 Y{svv.one_dock_y} F3000 _SERVO_SELECT G0 X{svv.one_select_x + 8} F12000 _PRIME #_WIPE G0 X0 F12000 {% if "xyz" in printer.toolhead.homed_axes %} SET_GCODE_OFFSET X={svv.one_x_offset} SET_GCODE_OFFSET Y={svv.one_y_offset} SET_GCODE_OFFSET Z={svv.one_z_offset} {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=1 SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE=1 _POST_SELECT_CHECK TOOL=1 {% endif %}
[gcode_macro _DOCK_PH2] gcode: _CHOME_TOOL {% set svv = printer.save_variables.variables %} _RETRACT _ZHOP _OFFSET_RESET G90 G0 Y{svv.one_dock_y} F20000 G0 X{svv.one_dock_x + 31} F20000 G0 X{svv.one_dock_x} F2000 _SERVO_DOCK G0 Y{svv.one_select_y} F4000 G0 X{svv.one_dock_x + 10} F12000 G0 X15 F20000
[gcode_macro SELECT_PH3] gcode: _PRE_SELECT_CHECK TOOL=2 _SELECT_PH3
[gcode_macro _SELECT_PH3] gcode: {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 and printer["gcode_macro _toolchanger_state"].already_selected|int == 0 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder2 G90 G0 Y{svv.two_select_y} F20000 G0 X{svv.two_select_x + 50} F20000 G0 X{svv.two_select_x + 7} F10000 G0 X{svv.two_select_x} F3000 G0 Y{svv.two_dock_y} F3000 _SERVO_SELECT G0 X{svv.two_select_x + 8} F12000 _PRIME #_WIPE G0 X0 F12000 {% if "xyz" in printer.toolhead.homed_axes %} SET_GCODE_OFFSET X={svv.two_x_offset} SET_GCODE_OFFSET Y={svv.two_y_offset} SET_GCODE_OFFSET Z={svv.two_z_offset} {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=2 SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE=2 _POST_SELECT_CHECK TOOL=2 {% endif %}
[gcode_macro _DOCK_PH3] gcode: _CHOME_TOOL {% set svv = printer.save_variables.variables %} _RETRACT _ZHOP _OFFSET_RESET G90 G0 Y{svv.two_dock_y} F20000 G0 X{svv.two_dock_x + 31} F20000 G0 X{svv.two_dock_x} F2000 _SERVO_DOCK G0 Y{svv.two_select_y} F4000 G0 X{svv.two_dock_x + 15} F12000 G0 X15 F20000
[gcode_macro SELECT_PH4] gcode: _PRE_SELECT_CHECK TOOL=3 _SELECT_PH4
[gcode_macro _SELECT_PH4] gcode: {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 and printer["gcode_macro _toolchanger_state"].already_selected|int == 0 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder3 G90 G0 Y{svv.three_select_y} F20000 G0 X{svv.three_select_x + 50} F20000 G0 X{svv.three_select_x + 7} F10000 G0 X{svv.three_select_x} F3000 G0 Y{svv.three_dock_y} F3000 _SERVO_SELECT G0 X{svv.three_select_x + 8} F12000 _PRIME #_WIPE G0 X0 F12000 {% if "xyz" in printer.toolhead.homed_axes %} SET_GCODE_OFFSET X={svv.three_x_offset} SET_GCODE_OFFSET Y={svv.three_y_offset} SET_GCODE_OFFSET Z={svv.three_z_offset} {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=3 SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE=3 _POST_SELECT_CHECK TOOL=3 {% endif %}
[gcode_macro _DOCK_PH4] gcode: _CHOME_TOOL {% set svv = printer.save_variables.variables %} _RETRACT _ZHOP _OFFSET_RESET G90 G0 Y{svv.three_dock_y} F20000 G0 X{svv.three_dock_x + 31} F20000 G0 X{svv.three_dock_x} F2000 _SERVO_DOCK G0 Y{svv.three_select_y} F4000 G0 X{svv.three_dock_x + 15} F12000 G0 X15 F20000
[gcode_macro SELECT_PH5] gcode: _PRE_SELECT_CHECK TOOL=4 _SELECT_PH5
[gcode_macro _SELECT_PH5] gcode: {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 and printer["gcode_macro _toolchanger_state"].already_selected|int == 0 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder4 G90 G0 Y{svv.four_select_y} F20000 G0 X{svv.four_select_x + 50} F20000 G0 X{svv.four_select_x + 7} F10000 G0 X{svv.four_select_x} F3000 G0 Y{svv.four_dock_y} F3000 _SERVO_SELECT G0 X{svv.four_select_x + 8} F12000 _PRIME #_WIPE G0 X0 F12000 {% if "xyz" in printer.toolhead.homed_axes %} SET_GCODE_OFFSET X={svv.four_x_offset} SET_GCODE_OFFSET Y={svv.four_y_offset} SET_GCODE_OFFSET Z={svv.four_z_offset} {% endif %} SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE=4 SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE=4 _POST_SELECT_CHECK TOOL=4 {% endif %}
[gcode_macro _DOCK_PH5] gcode: _CHOME_TOOL {% set svv = printer.save_variables.variables %} _RETRACT _ZHOP _OFFSET_RESET G90 G0 Y{svv.four_dock_y} F20000 G0 X{svv.four_dock_x + 31} F20000 G0 X{svv.four_dock_x} F2000 _SERVO_DOCK G0 Y{svv.four_select_y} F4000 G0 X{svv.four_dock_x + 15} F12000 G0 X15 F20000
############################## Carriage & Print Head Switch Logic ###############################
[gcode_macro toolchanger_sensor_status] gcode: {% set svv = printer.save_variables.variables %} {% set active_tools = svv.active_tools|default(5)|int %}
{% set t0 = printer["gcode_button t0_dock_sensor"].state if active_tools > 0 else "N/A" %} {% set t1 = printer["gcode_button t1_dock_sensor"].state if active_tools > 1 else "N/A" %} {% set t2 = printer["gcode_button t2_dock_sensor"].state if active_tools > 2 else "N/A" %} {% set t3 = printer["gcode_button t3_dock_sensor"].state if active_tools > 3 else "N/A" %} {% set t4 = printer["gcode_button t4_dock_sensor"].state if active_tools > 4 else "N/A" %}
{ action_respond_info( "Carriage=" ~ printer["gcode_button carriage_tool_sensor"].state ~ " | PH1=" ~ t0 ~ " | PH2=" ~ t1 ~ " | PH3=" ~ t2 ~ " | PH4=" ~ t3 ~ " | PH5=" ~ t4 ) }
[gcode_macro _TOOLCHANGER_PAUSE] gcode: {% set msg = params.MSG|default("toolchanger_error")|replace("_", " ") %} { action_respond_info(msg) } M117 {msg} {% if printer.print_stats.state == "printing" %} PAUSE_BASE {% endif %}
[gcode_macro _toolchanger_state] variable_can_continue: 1 variable_already_selected: 0 gcode:
[gcode_macro DOCK] gcode: {% set svv = printer.save_variables.variables %} {% set active_tools = svv.active_tools|default(0)|int %} {% set carriage = printer["gcode_button carriage_tool_sensor"].state %}
_TOOLCHANGER_CLEAR_PENDING SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1
{% if active_tools < 1 %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=active_tools_is_invalid
{% else %} {% set t0_docked = 1 if active_tools > 0 and printer["gcode_button t0_dock_sensor"].state == "PRESSED" else 0 %} {% set t1_docked = 1 if active_tools > 1 and printer["gcode_button t1_dock_sensor"].state == "PRESSED" else 0 %} {% set t2_docked = 1 if active_tools > 2 and printer["gcode_button t2_dock_sensor"].state == "PRESSED" else 0 %} {% set t3_docked = 1 if active_tools > 3 and printer["gcode_button t3_dock_sensor"].state == "PRESSED" else 0 %} {% set t4_docked = 1 if active_tools > 4 and printer["gcode_button t4_dock_sensor"].state == "PRESSED" else 0 %} {% set docked_count = t0_docked + t1_docked + t2_docked + t3_docked + t4_docked %}
{% set t0_open = 1 if active_tools > 0 and printer["gcode_button t0_dock_sensor"].state == "RELEASED" else 0 %} {% set t1_open = 1 if active_tools > 1 and printer["gcode_button t1_dock_sensor"].state == "RELEASED" else 0 %} {% set t2_open = 1 if active_tools > 2 and printer["gcode_button t2_dock_sensor"].state == "RELEASED" else 0 %} {% set t3_open = 1 if active_tools > 3 and printer["gcode_button t3_dock_sensor"].state == "RELEASED" else 0 %} {% set t4_open = 1 if active_tools > 4 and printer["gcode_button t4_dock_sensor"].state == "RELEASED" else 0 %} {% set open_count = t0_open + t1_open + t2_open + t3_open + t4_open %}
{% if carriage != "PRESSED" %} {% if docked_count == active_tools %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1 { action_respond_info("all installed print heads are already docked") } {% else %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_empty_but_not_all_installed_print_heads_read_docked {% endif %}
{% elif open_count == 0 %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_triggered_but_all_installed_print_heads_read_docked
{% elif open_count > 1 %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=multiple_installed_print_heads_read_undocked_cannot_determine_which_head_to_dock
{% else %} {% if t0_open %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_lost_before_docking_PH1 {% else %} _DOCK_PH1 {% set tool = 0 %} {% endif %} {% elif t1_open %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_lost_before_docking_PH2 {% else %} _DOCK_PH2 {% set tool = 1 %} {% endif %} {% elif t2_open %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_lost_before_docking_PH3 {% else %} _DOCK_PH3 {% set tool = 2 %} {% endif %} {% elif t3_open %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state
elif t3_open %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_lost_before_docking_PH4 {% else %} _DOCK_PH4 {% set tool = 3 %} {% endif %} {% else %} {% if printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_lost_before_docking_PH5 {% else %} _DOCK_PH5 {% set tool = 4 %} {% endif %} {% endif %}
{% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} M400 SET_GCODE_VARIABLE MACRO=_post_dock_state VARIABLE=tool VALUE={tool} UPDATE_DELAYED_GCODE ID=_delayed_post_dock_check DURATION=0.1 {% endif %} {% endif %} {% endif %}
[gcode_macro _PRE_SELECT_CHECK] gcode: {% set tool = params.TOOL|int %} {% set svv = printer.save_variables.variables %} {% set active_tools = svv.active_tools|default(0)|int %} {% set carriage_pressed = 1 if printer["gcode_button carriage_tool_sensor"].state == "PRESSED" else 0 %} {% set dock_sensor = "gcode_button t" ~ tool ~ "_dock_sensor" %}
_TOOLCHANGER_CLEAR_PENDING SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1 SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=already_selected VALUE=0
{% if tool < 0 or tool >= active_tools %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"PH" ~ (tool + 1) ~ "_is_not_installed"}
{% elif carriage_pressed and printer[dock_sensor].state == "RELEASED" %} { action_respond_info("PH" ~ (tool + 1) ~ " is already selected, skipping dock and reselect") } M117 PH{tool + 1} already selected SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=already_selected VALUE=1
{% else %} {% if carriage_pressed %} DOCK {% else %} {% if printer[dock_sensor].state == "PRESSED" %} _SERVO_DOCK {% endif %} {% endif %} _PRE_SELECT_VERIFY TOOL={tool} {% endif %}
[gcode_macro _PRE_SELECT_VERIFY] gcode: {% set tool = params.TOOL|int %} {% set name = "gcode_button t" ~ tool ~ "_dock_sensor" %}
M400 G4 P300
{% if printer["gcode_macro _toolchanger_state"].can_continue|int == 0 %} { action_respond_info("pre-select check failed") }
{% elif printer["gcode_button carriage_tool_sensor"].state == "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=carriage_still_occupied_after_docking
{% elif printer[name].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"PH" ~ (tool + 1) ~ "_is_not_docked_cannot_select"}
{% else %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1 { action_respond_info("pre-select check passed for PH" ~ (tool + 1)) } {% endif %}
[gcode_macro _post_select_state] variable_tool: -1 gcode:
[gcode_macro _post_dock_state] variable_tool: -1 gcode:
[gcode_macro _TOOLCHANGER_CLEAR_PENDING] gcode: UPDATE_DELAYED_GCODE ID=_delayed_post_select_check DURATION=0 UPDATE_DELAYED_GCODE ID=_delayed_post_dock_check DURATION=0 SET_GCODE_VARIABLE MACRO=_post_select_state VARIABLE=tool VALUE=-1 SET_GCODE_VARIABLE MACRO=_post_dock_state VARIABLE=tool VALUE=-1 SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=already_selected VALUE=0
[gcode_macro _POST_SELECT_CHECK] gcode: {% set tool = params.TOOL|int %} M400 SET_GCODE_VARIABLE MACRO=_post_select_state VARIABLE=tool VALUE={tool} UPDATE_DELAYED_GCODE ID=_delayed_post_select_check DURATION=0.1
[delayed_gcode _delayed_post_select_check] gcode: {% set tool = printer["gcode_macro _post_select_state"].tool|int %} {% set name = "gcode_button t" ~ tool ~ "_dock_sensor" %}
{% if tool < 0 %} { action_respond_info("post select check skipped, invalid tool") }
{% elif printer["gcode_button carriage_tool_sensor"].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"pickup_failed_carriage_switch_not_triggered_for_PH" ~ (tool + 1)}
{% elif printer[name].state != "RELEASED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"pickup_failed_PH" ~ (tool + 1) ~ "_still_reads_docked"}
{% else %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1 { action_respond_info("PH" ~ (tool + 1) ~ " selected successfully") } {% endif %}
SET_GCODE_VARIABLE MACRO=_post_select_state VARIABLE=tool VALUE=-1
[delayed_gcode _delayed_post_dock_check] gcode: {% set tool = printer["gcode_macro _post_dock_state"].tool|int %} {% set name = "gcode_button t" ~ tool ~ "_dock_sensor" %}
{% if tool < 0 %} { action_respond_info("post dock check skipped, invalid tool") }
{% elif printer["gcode_button carriage_tool_sensor"].state != "RELEASED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"dock_failed_carriage_still_triggered_after_docking_PH" ~ (tool + 1)}
{% elif printer[name].state != "PRESSED" %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG={"dock_failed_PH" ~ (tool + 1) ~ "_switch_not_triggered_after_docking"}
{% else %} SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=1 { action_respond_info("PH" ~ (tool + 1) ~ " docked successfully") } {% endif %}
SET_GCODE_VARIABLE MACRO=_post_dock_state VARIABLE=tool VALUE=-1
# PRIME and WIPE Commands
[gcode_macro _PRIME_PH1] description: Pick up PH1, move to X=-92, prime 25mm, wipe pattern, then dock gcode: _PRE_SELECT_CHECK TOOL=0 {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder G90 G0 Y{svv.zero_select_y} F20000 G0 X{svv.zero_select_x + 50} F20000 G0 X{svv.zero_select_x + 7} F10000 G0 X{svv.zero_select_x} F3000 G0 Y{svv.zero_dock_y} F3000 _SERVO_SELECT # Tool is now locked to carriage but still on pins _PRIME_AND_WIPE TOOL=0 {% endif %}
[gcode_macro _PRIME_PH2] gcode: _PRE_SELECT_CHECK TOOL=1 {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder1 G90 G0 Y{svv.one_select_y} F20000 G0 X{svv.one_select_x + 50} F20000 G0 X{svv.one_select_x + 7} F10000 G0 X{svv.one_select_x} F3000 G0 Y{svv.one_dock_y} F3000 _SERVO_SELECT _PRIME_AND_WIPE TOOL=1 {% endif %}
[gcode_macro _PRIME_PH3] gcode: _PRE_SELECT_CHECK TOOL=2 {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder2 G90 G0 Y{svv.two_select_y} F20000 G0 X{svv.two_select_x + 50} F20000 G0 X{svv.two_select_x + 7} F10000 G0 X{svv.two_select_x} F3000 G0 Y{svv.two_dock_y} F3000 _SERVO_SELECT _PRIME_AND_WIPE TOOL=2 {% endif %}
[gcode_macro _PRIME_PH4] gcode: _PRE_SELECT_CHECK TOOL=3 {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder3 G90 G0 Y{svv.three_select_y} F20000 G0 X{svv.three_select_x + 50} F20000 G0 X{svv.three_select_x + 7} F10000 G0 X{svv.three_select_x} F3000 G0 Y{svv.three_dock_y} F3000 _SERVO_SELECT _PRIME_AND_WIPE TOOL=3 {% endif %}
[gcode_macro _PRIME_PH5] gcode: _PRE_SELECT_CHECK TOOL=4 {% if printer["gcode_macro _toolchanger_state"].can_continue|int == 1 %} _CHOME_TOOL {% set svv = printer.save_variables.variables %} ACTIVATE_EXTRUDER EXTRUDER=extruder4 G90 G0 Y{svv.four_select_y} F20000 G0 X{svv.four_select_x + 50} F20000 G0 X{svv.four_select_x + 7} F10000 G0 X{svv.four_select_x} F3000 G0 Y{svv.four_dock_y} F3000 _SERVO_SELECT _PRIME_AND_WIPE TOOL=4 {% endif %}
[gcode_macro _PRIME_AND_WIPE] description: Internal macro - clear pins, move to X=-92, prime 25mm, retract 2mm, wipe 6x, then dock gcode: {% set tool = params.TOOL|int %} {% set svv = printer.save_variables.variables %} # Get tool-specific dock coordinates {% if tool == 0 %} {% set dock_x = svv.zero_dock_x %} {% set dock_y = svv.zero_dock_y %} {% set select_x = svv.zero_select_x %} {% elif tool == 1 %} {% set dock_x = svv.one_dock_x %} {% set dock_y = svv.one_dock_y %} {% set select_x = svv.one_select_x %} {% elif tool == 2 %} {% set dock_x = svv.two_dock_x %} {% set dock_y = svv.two_dock_y %} {% set select_x = svv.two_select_x %} {% elif tool == 3 %} {% set dock_x = svv.three_dock_x %} {% set dock_y = svv.three_dock_y %} {% set select_x = svv.three_select_x %} {% elif tool == 4 %} {% set dock_x = svv.four_dock_x %} {% set dock_y = svv.four_dock_y %} {% set select_x = svv.four_select_x %} {% else %} { action_respond_info("_PRIME_AND_WIPE: Invalid tool index") } SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=invalid_tool_for_prime_and_wipe
index") } SET_GCODE_VARIABLE MACRO=_toolchanger_state VARIABLE=can_continue VALUE=0 _TOOLCHANGER_PAUSE MSG=invalid_tool_for_prime_and_wipe {% endif %} # Clear pins first - move to select_x + 8 (same as original SELECT_PH macros) G90 G0 X{select_x + 8} F12000 # Now move to X=-92 for priming (stay at dock_y) G1 X-92 F9000 G1 Y{dock_y} F9000 # Re-assure Y position (should already be there) # Check temperature - if below 180°C, heat to 200°C {% set current_temp = printer[printer.toolhead.extruder].temperature %} {% if current_temp < 180 %} { action_respond_info("PRIME_AND_WIPE: Tool T" ~ tool ~ " temp is " ~ current_temp ~ "°C, heating to 200°C") } {% if tool == 0 %} {% set sensor_name = "extruder" %} {% elif tool == 1 %} {% set sensor_name = "extruder1" %} {% elif tool == 2 %} {% set sensor_name = "extruder2" %} {% elif tool == 3 %} {% set sensor_name = "extruder3" %} {% elif tool == 4 %} {% set sensor_name = "extruder4" %} {% endif %} M104 S200 T{tool} TEMPERATURE_WAIT SENSOR={sensor_name} MINIMUM=200 {% endif %} # Prime: extrude 25mm at 10mm/s (F600) G92 E0
} M104 S200 T{tool} TEMPERATURE_WAIT SENSOR={sensor_name} MINIMUM=200 {% endif %} # Prime: extrude 25mm at 10mm/s (F600) G92 E0 G1 E25 F600 G92 E0 # Retract: 2mm at 40mm/s (F2400) G1 E-2 F2400 G92 E0 # Wipe pattern: move X from -92 to -84 and back (8mm total), 4 times at F=6000 # No Y movement - stays at dock_y G91 G1 X+8 F6000 G1 X-8 F6000 G1 X+8 F6000 G1 X-8 F6000 G1 X+8 F6000 G1 X-8 F6000 G1 X+8 F6000 G1 X-8 F6000 G90 # Final retract to prevent oozing during docking G92 E0 G1 E-0.5 F1500 G92 E0 # Now dock the tool DOCK SET_GCODE_VARIABLE MACRO=RESUME VARIABLE=extruder_restore_tool VALUE={tool} SET_GCODE_VARIABLE MACRO=_RESUME_WIPE VARIABLE=extruder_restore_tool VALUE={tool}