taz5 macros.cfg

🧩 Syntax:
########################################
#       macros.cfg --this works but is a 
#       disaster and needs to be cleaned
#       up for the stock taz5
########################################

##############################
#       PAUSE_PRINT_MACRO
##############################
[gcode_macro PAUSE]
description: Pause the actual running print
rename_existing: PAUSE_BASE
variable_extrude: 1.0 ;change this number if you need to extrude more or less filament
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 *** 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_PRINT_MACRO
##############################
[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 *** enough")}
  {% endif %}
  RESUME_BASE {get_params}

##############################
#       CANCEL_PRINT_MACRO
##############################
[gcode_macro CANCEL_PRINT]
description: Cancel the actual running print
rename_existing: CANCEL_PRINT_BASE
gcode:
  TURN_OFF_HEATERS
  CLEAR_PAUSE
  SDCARD_RESET_FILE
  CANCEL_PRINT_BASE
  G1 Z25 F300 ;move Z up 25mm from print


##############################
# PRINTER_POWER_OFF_MACRO
##############################
[gcode_macro POWER_OFF_PRINTER]
gcode:
    {action_call_remote_method("set_device_power", device="printer", state="off")}


##############################
#       BED_LEVEL_MACRO
##############################
#       [gcode_macro LEVEL_BED]
#       gcode:
#               SCREWS_TILT_CALCULATE


##############################
#       START_PRINT
##############################
# Replace the slicer's custom start and end g-code scripts with START_PRINT.
# # start_print BED_TEMP={first_layer_bed_temperature} EXTRUDER_TEMP={first_layer_temperature}
# # BED_MESH_CALIBRATE PRINT_MIN={params.PRINT_MIN} PRINT_MAX={params.PRINT_MAX} FORCE_NEW_MESH=True
# # Use the above b_m_c for print_area_bed_mesh.cfg

[gcode_macro START_PRINT]
gcode:
    {% set BED_TEMP = params.BED|default(50)|float %}
    {% set EXTRUDER_TEMP = params.EXTRUDER|default(200)|float %}
        {% set FILAMENT_TYPE = params.FILAMENT|default(PLA)|string %}
        G90 ; use absolute coordinates
    M83 ; extruder relative mode
    ; Set Extruder and Bed Temperature
    M104 S200 ; {EXTRUDER_TEMP[0]-50}
    M140 S50 ; {BED_TEMP}
        G28 ; home all
    M190 S{BED_TEMP}
    M109 S{EXTRUDER_TEMP}
    G1 Z5 F1500 E2 ;move Z up 5 to prevent scratching of surface, extrude 2mm
    G1 X1.0 Y10.0 Z0.30 F5000 ;move to start-line position
    G1 X1.0 Y110.0 Z0.30 F1500 E8 ;draw 1st Y line
    G1 X1.5 Y110.0 Z0.30 F5000 ;move to side a little
    G1 X1.5 Y10.0 Z0.30 F1500 E16 ;draw 2nd Y line
#           G1 X101.5 Y10.0 Z0.30 F1500 E24 ;draw 3rd (1st X) line
#           G1 X101.5 Y10.5 Z0.30 F5000 ;move to side a little
#           G1 X1.5 Y10.5 Z0.30 F1500 ;E32 draw 4th (2nd X) line
    G1 Z5 F300 ;move z up a bit after purge line

#gcode:
#    {% set BED_TEMP = params.BED_TEMP|default(58)|float %}
#    {% set EXTRUDER_TEMP = params.EXTRUDER_TEMP|default(220)|float %}
#    G90 ;Use absolute coordinates
#    M140 S{BED_TEMP} ;Start heating bed to temp
#    M109 S{EXTRUDER_TEMP[0]-50} ;Set and wait for extruder to temp minus fifty
#    M190 S{BED_TEMP} ;Set and wait for bed to reach temperature
#    G28 ;Home the printer
#    BED_MESH_PROFILE LOAD=bedmesh
#    M109 S{EXTRUDER_TEMP[0]} ;Set and wait for nozzle to get to temp
#    G92 E0 ;reset extruder
#    G1 Z5 F1500 E2 ;move Z up 5 to prevent scratching of surface, extrude 2mm
#    G1 X12.0 Y10.0 Z0.35 F5000 ;move to start-line position
#    G1 X12.0 Y110.0 Z0.35 F1500 E8 ;draw 1st line
#    G1 X12.4 Y110.0 Z0.35 F5000 ;move to side a little
#    G1 X12.4 Y10.0 Z0.35 F1500 E16 ;draw 2nd line
#    G1 X120.4 Y10.0 Z0.35 F1500 E24 ;draw 3rd line
#    G1 X120.4 Y10.4 Z0.35 F5000 ;move to side a little
#    G1 X12.8 Y10.4 Z0.35 F1500 E32 ;draw 4th line
#    G1 Z5 F300 ;move z up a bit after purge line


##############################
#       END_PRINT
##############################
# Replace the slicer's custom start and end g-code scripts with END_PRINT.
# end_print
[gcode_macro END_PRINT]
gcode:
    # Turn off bed, extruder, and fan
    M140 S0
    M104 S0
    M106 S0
    # Move nozzle away from print while retracting
    G91
    G1 X-2 Y-2 E-2 F300
    # Raise nozzle by 15mm
    G1 Z15 F3000
    G90
    G27 # Park Toolhead
    G0 Y250
    # Alternatively
    # G27 Z={printer.toolhead.position.z} # Park toolhead at current height (top of print + 10mm)
    # Disable steppers
    M84

#############################
# Park Toolhead
##############################
[gcode_macro G27]
gcode:
  {% set default_x = printer.toolhead.axis_minimum.x + 5 %} # default X coordinates
  {% set default_y = printer.toolhead.axis_maximum.y %} # default Y coordinates

  {% 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 %}

##############################
# 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(50)|int %}
   {% set y = params.X|default(0)|int %}
   {% set z = params.X|default(10)|int %}
   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-50 F1000
   RESTORE_GCODE_STATE NAME=M600_state
[gcode_macro LOAD_FILAMENT]
gcode:
   M83                            ; set extruder to relative
   G1 E50 F1800                   ; quickly load filament to down bowden
   G1 E30 F300                    ; slower extrusion for hotend path
   G1 E15 F150                    ; prime nozzle with filament
   M82                            ; set extruder to absolute
[gcode_macro UNLOAD_FILAMENT]
gcode:
   M83                            ; set extruder to relative
   G1 E10 F300                    ; extrude a little to soften tip
   G1 E-380 F1800                 ; retract filament completely
   M82                            ; set extruder to absolute