Skip to content

Instantly share code, notes, and snippets.

@epoxi
Created May 5, 2023 03:12
Show Gist options
  • Save epoxi/ca34f5316756b39ebca06404af3c147f to your computer and use it in GitHub Desktop.
Save epoxi/ca34f5316756b39ebca06404af3c147f to your computer and use it in GitHub Desktop.
macros.cfg
######################################################################
# PAUSE
######################################################################
[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
# change this if you need more or less extrusion
variable_extrude: 1.0
gcode:
##### read E from pause macro #####
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
##### set park positon for x and y #####
# default is your max posion from your printer.cfg
{% set x_park = printer.toolhead.axis_maximum.x|float - 5.0 %}
{% set y_park = printer.toolhead.axis_maximum.y|float - 5.0 %}
##### calculate save lift position #####
{% set max_z = printer.toolhead.axis_maximum.z|float %}
{% set act_z = printer.toolhead.position.z|float %}
{% if act_z < (max_z - 2.0) %}
{% set z_safe = 2.0 %}
{% else %}
{% set z_safe = max_z - act_z %}
{% endif %}
##### end of definitions #####
PAUSE_BASE
G91
{% if printer.extruder.can_extrude|lower == 'true' %}
G1 E-{E} F2100
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
{% if "xyz" in printer.toolhead.homed_axes %}
G1 Z{z_safe} F900
G90
G1 X{x_park} Y{y_park} F6000
{% else %}
{action_respond_info("Printer not homed")}
{% endif %}
######################################################################
# RESUME
######################################################################
[gcode_macro RESUME]
description: Resume the actual running print
rename_existing: RESUME_BASE
gcode:
##### read E from pause macro #####
{% set E = printer["gcode_macro PAUSE"].extrude|float %}
#### get VELOCITY parameter if specified ####
{% if 'VELOCITY' in params|upper %}
{% set get_params = ('VELOCITY=' + params.VELOCITY) %}
{%else %}
{% set get_params = "" %}
{% endif %}
##### end of definitions #####
{% if printer.extruder.can_extrude|lower == 'true' %}
G91
G1 E{E} F2100
{% else %}
{action_respond_info("Extruder not hot enough")}
{% endif %}
RESUME_BASE {get_params}
[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
TURN_OFF_HEATERS
CANCEL_PRINT_BASE
######################################################################
# G27 - PARK TOOLHEAD
######################################################################
[gcode_macro G27]
gcode:
{% set default_x = printer.toolhead.axis_minimum.x %}
{% set default_y = printer.toolhead.axis_minimum.y %}
{% if 'save_variables' in printer %}
{% set svv = printer.save_variables.variables %}
{% if 'park_x' in svv %}
{% set default_x = svv.park_x %}
{% endif %}
{% if 'park_y' in svv %}
{% set default_y = svv.park_y %}
{% endif %}
{% endif %}
{% set x = params.X|default(default_x)|float %}
{% set y = params.Y|default(default_y)|float %}
{% set z = params.Z|default(20)|float %}
{% if printer.toolhead.homed_axes != "xyz" %}
{action_respond_info("Please home XYZ first")}
{% else %}
SAVE_GCODE_STATE NAME=G27_state
G91
G1 Z{z}
G90
G1 X{x} Y{y} F3000
RESTORE_GCODE_STATE NAME=G27_state MOVE=0
{% endif %}
######################################################################
# LOAD FILAMENT
######################################################################
[gcode_macro LOAD_FILAMENT]
#
# LOAD_FILAMENT
#
# Heat to 200°C then prime the nozzle
description: Load filament (heat nozzle if necessary)
gcode:
M117 Loading filament...
{% if printer[printer.toolhead.extruder].temperature < 200.0 %}
STATUS_HEATING
M117 Heating hotend...
SET_HEATER_TEMPERATURE HEATER='extruder' TARGET=200
TEMPERATURE_WAIT SENSOR='extruder' MINIMUM=200
{%endif%}
STATUS_BUSY
M117 Loading filament...
M83 ; set extruder to relative
G1 E850 F1000 ; Cargar el bowden
G1 E40 F300 ; slower extrusion for hotend path
G1 E15 F150 ; prime nozzle with filament
M82 ; set extruder to absolute
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=10
STATUS_READY
######################################################################
# UNLOAD FILAMENT
######################################################################
[gcode_macro UNLOAD_FILAMENT]
#
# UNLOAD_FILAMENT
#
# Heat the nozzle to 230°C then retract the filament out of the toolhead
#
description: Heat the nozzle (if needed), then retract the filament out of the toolhead
gcode:
SAVE_GCODE_STATE NAME=UNLOAD_FILAMENT
{% if printer[printer.toolhead.extruder].temperature < 230.0 %}
STATUS_HEATING
M117 Heating hotend...
SET_HEATER_TEMPERATURE HEATER='extruder' TARGET=230
TEMPERATURE_WAIT SENSOR='extruder' MINIMUM=230
{% endif %}
STATUS_BUSY
M117 Unloading filament...
M83 ; set extruder to relative
G1 E2 F300 ; extrude a little to soften tip
G1 E-50 F200 ; Retract 50mm at slow speed (cool down filament tip)
G1 E-850 F1800 ; retract filament completely
#M82 ; set extruder to absolute
UPDATE_DELAYED_GCODE ID=_CLEAR_DISPLAY DURATION=10
RESTORE_GCODE_STATE NAME=UNLOAD_FILAMENT MOVE=0
STATUS_READY
######################################################################
# Filament Change
######################################################################
# M600: Filament Change. This macro will pause the printer, move the
# tool to the change position, and retract the filament 50mm. Adjust
# the retraction settings for your own extruder. After filament has
# been changed, the print can be resumed from its previous position
# with the "RESUME" gcode.
[pause_resume]
[gcode_macro M600]
gcode:
{% set X = params.X|default(0)|float %}
{% set Y = params.Y|default(0)|float %}
{% set Z = params.Z|default(10)|float %}
SAVE_GCODE_STATE NAME=M600_state
PAUSE
G91
G1 E-.8 F2700
G1 Z{Z}
G90
G1 X{X} Y{Y} F3000
G91
G1 E-4 F4200
G1 E-50 F300
G1 E-800 F3000
RESTORE_GCODE_STATE NAME=M600_state
######################################################################
# Wipe Line
######################################################################
[gcode_macro WIPE_LINE]
gcode:
{% set z = params.Z|default(0.25)|float %}
{% set n = params.N|default(0.4)|float %}
{% if printer.toolhead.homed_axes != "xyz" %}
{action_respond_info("Please home XYZ first")}
{% elif printer.extruder.temperature < 170 %}
{action_respond_info("Extruder temperature too low")}
{% else %}
SAVE_GCODE_STATE NAME=WIPE_LINE_state
M82
G90
G92 E0
G1 X10 Y200 Z5 F3000
G1 Z{z} F3000
G1 X200 Y200 F1500 E10.83
G1 X{ n + 10.0 } F5000
G1 Y198 F1500 E21.5
G1 Y200 F5000
RESTORE_GCODE_STATE NAME=WIPE_LINE_state MOVE=0
{% endif %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment