Skip to content

Instantly share code, notes, and snippets.

@unraze
Last active July 11, 2023 04:58
Show Gist options
  • Save unraze/801cb0402b67635d7566b2a1a3688a24 to your computer and use it in GitHub Desktop.
Save unraze/801cb0402b67635d7566b2a1a3688a24 to your computer and use it in GitHub Desktop.
[gcode_macro BACK]
gcode:
M876 S1
[gcode_macro NEXT]
gcode:
m876 S2
[gcode_macro CANCEL]
gcode:
m876 S1
[gcode_macro EXTRACT]
gcode:
m876 S3
############################################u
############################################u
############################################u
#------------------------------------------------------u
# MOM - My Overpowered M600 macro / written by Jay Lexx
# Also tenderly called the Mother Of Macros by u/Woodcat64
# Listen to MOM and everything will be alright!
#------------------------------------------------------
# NO RESPONSE TAKEN FOR ANY DAMAGE CAUSED BY MOM ;)
#------------------------------------------------------
#
#
# 09.11.2021 v0.1.6
#
# Sourcecode maintenance due to Klipper updates.
#
# v0.1.5
#
# - added ability to prevent nozzle cooldown
#
# Save this file f.e. as /home/pi/klipper_config/m600.cfg to leave printer.cfg nice and clean
# then use [include /home/pi/klipper_config/M600.cfg] in your printer.cfg
# Don't forget to configure default values in [gcode_makro m600cfg] down below
#
#
# Usage in CURA Slicer:
# Extensions > Post Processing > Modify G-Code
# Add a script -> Filament Change
# Set Layer to value at which filament should be changed
# I personally set the rest to 0, works like a charm
# ( Tbh, i even didn't check if they have any effect )
#
# The M600 command can also be used to just change filament from console or via Button, so,
# no more need for Unload,Park, Load etc. Macros anymore. The macro should return to the temp
# the printer had when it was started, regardless ff printer temperature at 0, 40 or 200
# It will check if temperature is high enough to extrude filament ( you have configured your
# min_extrude_temp in printer.cfg [extruder] didn't you ?!?), if not it will use the default
# temperature configured down below anyway.
#
#
# If the printer was not homed - therefore not knowing where it is - it will perform
# a G28 homing sequence . This will ( better say should ;) ) not happen mid print, don't worry.
#
# -----------------------------------------------------
# DESIGNED TO WORK ESPECIALLY WITH OCTOPRINT
# -----------------------------------------------------
# In Octoprint set Plugins -> Printer Dialogs -> Enable Support = Always
# Thx to u/josolanes for mentioning the fix for this possible issue
#
# Please apologize my english, i'm not a native speaker :)
#
# Those macros are in the magic box:
#
# [M876 S]
# Handle prompt response ( to communicate with octoprint )
#
# [JOBCENTER]
# Handles navigation inside the whole process ( better not to issue as terminal command )
#
# [M125]
# Park head
#
# [M701]
# Load filament
#
# [M702]
# Unload filament
#
# [LOW_TEMP_CHECK T]
# Heatup process & temperature processor
# uses printer.cfg [extruder] section max_temp & min_extrude_temp
#
# [M600]
# Marlin compatible guided Filament Change
#-------------------------------------------------------------------------
# Delete sections [respond] and [pause_resume] if already in your printer.cfg
# Both are needed to make MOM run the household and use social media ;)
#-------------------------------------------------------------------------
[pause_resume]
recover_velocity: 100
# When capture/restore is enabled, the speed at which to return to
# the captured position (in mm/s). Default is 50.0 mm/s.
[respond]
#default_type: echo
# Sets the default prefix of the "M118" and "RESPOND" output to one
# of the following:
# echo: "echo: " (This is the default)
# command: "// "
# error: "!! "
#default_prefix: echo:
# Directly sets the default prefix. If present, this value will
# override the "default_type".
#-------------------------------------------------------------------------
#####################
[gcode_macro m600cfg]
#####################
# CONFIGURE YOUR PREFERRED DEFAULT VALUES INSIDE THIS GCODE_MACRO
# Couldn't find anywhere if or how it's possible to define a config section
# Would have been much nicer to deal with, maybe one day i'll find out :)
# Leave me a hint if you know how.
variable_default_temp: 220
# Default temperature to heat up if M600 issued in terminal
# Ignored if a target temperature is already set at launch ( M104 / M109 )
# or started within a printjob
variable_cooldown: 1
# Wether the hotende should cool down or not when pause started
# 1 - Hotend cools down when paused ( Recommended for security reasons and saves some energy if
# you're away a longer period of time and therefore can't change the filament)
# 0 - Hotend stays hot ( Not recommended, you never know... )
variable_x: 300
variable_y: 150
# Coordinates to park hotend at (as absolute values)
variable_z: 10
# mm to raise z from current height (this is a relative value!)
variable_zmin: 70
# if current z height is below zmin (as an absolute value), head will lift zmin ( as relative value) instead z
# making it easier to clean the nozzle at that height
variable_load_fast: 6
# mm to load filament at fast speed (length of bowden-hotend-purge)
variable_load_slow: 1
# mm to load filament after fast speed slowly into the hotend incl. purge
variable_bowden: 25
# total mm to unload filament (all at high speed)
variable_speed_1: 6000
# Speed at which filament is loaded/unloaded
variable_speed_2: 9000
# Speed at which hotend is moved to park position
variable_purge: 20
# Possibility to extract xx mm filament after loading if loading was too short f.e.
variable_output: 118
#Additional output send via M117 or M118
# !-ATTENTION--------------------------------------------------------!
# ! !
# ! Uncomment the desired language / Comment ( Delete ) the other !
# ! If you edit the language please don't use special characters !
# ! like Ü,Ö,Ä, Ǣ or É in your language,macro will not work and show !
# ! a UnicodeDecodeError: 'ascii' ... !
# !------------------------------------------------------------------!
# Textdata HTML UI deutsch (german)
#variable_step_a1: "<CENTER><P><B>SCHRITT 1/3 </B></P><H2>ZEIT ZU WECHSELN</H2>"
#variable_step_b1:"Achtung, der Druckkopf ist ggfs. heiss!<dl><dt>"
#variable_step_c1:"Die Temperatur wurde zur Sicherheit auf 0 gesetzt<dl><dt>"
#variable_step_d1:"Klicke <b>WEITER</B> um (wieder) aufzuheizen<BR> Klipper wird anschliessend das Filament entladen<BR><BR>"
#variable_step_2: "<CENTER><P><B>SCHRITT 2/3</B></P><B>Lade jetzt das neue Filament und klicke auf WEITER<BR><BR>( +/- 10mm in den PTFE Schlauch)"
#variable_step_3: "<CENTER><P><B>SCHRITT 3/3</B></P><B>Reinige den Druckkopf, klicke dann WEITER um mit dem Druck fortzufahren oder ZURUECK um zum vorherigen Schritt 2 zu gelangen."
#variable_next: "WEITER"
#variable_previous: "ZURUECK"
#variable_cancel: "ABBRUCH"
#variable_purgetext: "EXTRAHIERE"
# Textdata HTML UI english
variable_step_a1: "<CENTER><P><B>STEP 1/3 </B></P><H2>TIME TO CHANGE</H2>"
variable_step_b1:"Beware, the nozzle could be hot! <dl><dt>"
variable_step_c1:"Temperature set to 0 for security reasons<dl><dt>"
variable_step_d1:"Click <b>NEXT</B> to heat up (again)<BR> Klipper will then unload the filament<BR><BR>"
variable_step_2: "<CENTER><P><B>STEP 2/3</B></P><B>Load the new filament and click NEXT<BR><BR>( +/- 10mm into PTFE tube)"
variable_step_3: "<CENTER><P><B>STEP 3/3</B></P><B>Wipe nozzle clean, then click NEXT to resume print or click BACK to unload again and return to step 2"
variable_next: "NEXT"
variable_previous: "BACK"
variable_cancel: "CANCEL"
variable_purgetext: "EXTRACT"
gcode:
#-# * * * THERE SHOULD BE NO NEED TO EDIT ANYTHING BELOW THIS POINT * * * #-#
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=default_temp VALUE={default_temp}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=cooldown VALUE={cooldown}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=x VALUE={x}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=y VALUE={y}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=z VALUE={z}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=zmin VALUE={zmin}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=retract_fast VALUE={retract_fast}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=retract_slow VALUE={retract_slow}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=speed_1 VALUE={speed_1}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=speed_2 VALUE={speed_2}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=purge VALUE={purge}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=output VALUE={output}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_a1 VALUE={step_a1}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_b1 VALUE={step_b1}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_v1 VALUE={step_c1}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_d1 VALUE={step_d1}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_2 VALUE={step_2}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=step_3 VALUE={step_3}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=next VALUE={next}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=previous VALUE={previous}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=cancel VALUE={cancel}
SET_GCODE_VARIABLE MACRO=m600cfg VARIABLE=purgetext VALUE={purgetext}
#####################
[gcode_macro M876]
#####################
variable_myjob: 0
gcode:
{% set S = params.S|default(-1)|int %}
{% set myjob = printer["gcode_macro JOBCENTER"].job %}
{% if myjob != 0 %}
{% if S == 1 %}
{% set myjob = myjob-2 %} #Jump to previous Step
{% elif S == 2%}
{% elif S == 3%}
{% if myjob == 6003 %}
{% set myjob = 6004 %}
{% else %}
{% set myjob = 6003 %}
{% endif %}
{% endif %}
{% if myjob == 5999 %}
JOBCENTER NEWJOB=5999
{% elif myjob == 6001%}
JOBCENTER NEWJOB=6001
{% elif myjob == 6002%}
JOBCENTER NEWJOB=6002
{% elif myjob == 6003%}
JOBCENTER NEWJOB=6003
{% elif myjob == 6004%}
JOBCENTER NEWJOB=6004
{% endif %}
{% endif %}
#######################
[gcode_macro JOBCENTER]
#######################
variable_temperature: 0
variable_job: 0
variable_myjob: 0
variable_cool: 1
variable_mystep: 1
gcode:
RESPOND TYPE=echo MSG="Jobcenter recieved: {params.NEWJOB} "
{% set NEWJOB = params.NEWJOB|default(0)|int %}
{% set myjob = printer["gcode_macro JOBCENTER"].job %}
{% if NEWJOB == 6004 %}
M{printer["gcode_macro m600cfg"].output|int} Extracting ...
M83
G92 E0.0
G1 E{printer["gcode_macro m600cfg"].purge|int} F200
G92 E0.0
{% set NEWJOB=6005 %}
{% endif %}
{% if NEWJOB == 6003 %}
M{printer["gcode_macro m600cfg"].output|int} Restoring printer state
{% if printer["gcode_macro JOBCENTER"].temperature==0 %}
M109 S0
{% else %}
M109 S{printer["gcode_macro JOBCENTER"].temperature}
{% endif%}
RESUME
RESPOND TYPE=command MSG="action:notification Resuming print..."
{% set myjob=0 %}
{% endif %}
{% if ( NEWJOB == 6002 or NEWJOB == 6005) %}
{% if NEWJOB==6002 %}
M{printer["gcode_macro m600cfg"].output|int} Loading filament
M701
{% endif %}
RESPOND TYPE=command MSG="action:prompt_begin {printer["gcode_macro m600cfg"].step_3}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].next}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].previous}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].purgetext} {printer["gcode_macro m600cfg"].purge|int} mm"
RESPOND TYPE=command MSG="action:prompt_show"
{% set myjob=6003 %}
{% endif %}
{% if NEWJOB == 6001 %}
RESPOND TYPE=echo MSG="6001 entered"
LOW_TEMP_CHECK T={printer["gcode_macro JOBCENTER"].temperature}
RESPOND TYPE=echo MSG="emptying filament"
M{printer["gcode_macro m600cfg"].output|int} Unloading filament
M702
RESPOND TYPE=command MSG="action:prompt_begin {printer["gcode_macro m600cfg"].step_2}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].next}"
RESPOND TYPE=command MSG="action:prompt_show"
RESPOND TYPE=echo MSG="setting 6002"
{% set myjob=6002 %}
{% endif %}
{% if NEWJOB == 5999 %}
M{printer["gcode_macro m600cfg"].output|int} Restoring printer state
{% if printer["gcode_macro JOBCENTER"].temperature != 0 %}
LOW_TEMP_CHECK T={printer["gcode_macro JOBCENTER"].temperature} OVERRIDE=1
{% endif %}
RESUME
RESPOND TYPE=command MSG="action:notification M600 cancelled"
{% set myjob=0 %}
{% endif %}
{% if NEWJOB == 600 %}
PAUSE
M125
{% set cool=printer["gcode_macro m600cfg"].cooldown|int %}
{% set mystep=[printer["gcode_macro m600cfg"].step_a1,printer["gcode_macro m600cfg"].step_b1,printer["gcode_macro m600cfg"].step_d1]|join() %}
{% if cool != 0 %}
M104 S0
{% set mystep=[printer["gcode_macro m600cfg"].step_a1,printer["gcode_macro m600cfg"].step_c1,printer["gcode_macro m600cfg"].step_d1]|join() %}
{% endif %}
SET_IDLE_TIMEOUT TIMEOUT=7200
RESPOND TYPE=command MSG="action:prompt_begin {mystep}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].next}"
RESPOND TYPE=command MSG="action:prompt_choice {printer["gcode_macro m600cfg"].cancel}"
RESPOND TYPE=command MSG="action:prompt_show"
{% set myjob=6001 %}
{% endif %}
SET_GCODE_VARIABLE MACRO=JOBCENTER VARIABLE=job VALUE={myjob}
##################
[gcode_macro M125]
##################
gcode:
M{printer["gcode_macro m600cfg"].output|int} Moving hotend to {printer["gcode_macro m600cfg"].x|int}, {printer["gcode_macro m600cfg"].y|int}, {printer["gcode_macro m600cfg"].z|int} ({printer["gcode_macro m600cfg"].zmin|int})
SET_GCODE_VARIABLE MACRO=JOBCENTER VARIABLE=temperature VALUE={printer.extruder.target}
{% if printer.toolhead.homed_axes != "xyz" %}
# if not yet homed
M{printer["gcode_macro m600cfg"].output|int} Probably not printing. Homing needed ...
G28
{% endif %}
G91
# Note to self: Uncomment if ooze experienced (untested yet, just a logical thought)
# Retract small amount before moving if printer has a temperature set
{% if printer.extruder.target != 0 %}
LOW_TEMP_CHECK
G1 E-2 F1500
{% endif %}
{% if printer.toolhead.position.z|float + printer["gcode_macro m600cfg"].z|float < printer.configfile.config["stepper_z"]["position_max"]|float %}
{% if printer.toolhead.position.z < printer["gcode_macro m600cfg"].zmin|int %}
G1 Z{printer["gcode_macro m600cfg"].zmin|int|int-printer.toolhead.position.z|int}
{% else %}
SAVE_GCODE_STATE NAME=save_state
G1 Z{printer["gcode_macro m600cfg"].z|int}
RESTORE_GCODE_STATE NAME=save_state
{% endif %}
{% endif%}
G90
G1 X{printer["gcode_macro m600cfg"].x|int} Y{printer["gcode_macro m600cfg"].y|int} F{printer["gcode_macro m600cfg"].speed_2|int}
##################
[gcode_macro M701]
##################
gcode:
M83
G92 E0.0
LOW_TEMP_CHECK
G1 E{printer["gcode_macro m600cfg"].load_fast|int} F{printer["gcode_macro m600cfg"].speed_1|int}
G92 E0.0
G1 E{printer["gcode_macro m600cfg"].load_slow|int} F200
G92 E0.0
##################
[gcode_macro M702]
##################
gcode:
LOW_TEMP_CHECK
G91
G1 E10 F1200
G1 E-{printer["gcode_macro m600cfg"].bowden|int} F{printer["gcode_macro m600cfg"].speed_1|int}
G90
##################
[gcode_macro M600]
##################
gcode:
JOBCENTER NEWJOB=600
############################
[gcode_macro LOW_TEMP_CHECK]
############################
gcode:
{% if not params.OVERRIDE is defined %}
{% if params.T is defined %}
{% set TMP=params.T|int%}
{% if printer.configfile.config.extruder.max_temp is defined %}
{% if params.T|int>printer.configfile.config.extruder.max_temp|int %}
{% set TMP=printer["gcode_macro m600cfg"].default_temp|int %}
{% endif %}
{% endif %}
{% if TMP|int==0 %}
{% set TMP=printer["gcode_macro m600cfg"].default_temp|int %}
{% endif %}
{% else %}
{% set TMP=printer["gcode_macro m600cfg"].default_temp|int %}
{% if printer["gcode_macro JOBCENTER"].temperature|int > 0 %}
{% set TMP=printer["gcode_macro JOBCENTER"].temperature %}
{% endif %}
{% endif %}
{% if printer.configfile.config.extruder.min_extrude_temp is defined %}
{% if TMP|int<printer.configfile.config.extruder.min_extrude_temp|int %}
{% set TMP=printer["gcode_macro m600cfg"].default_temp %}
{% endif%}
{% endif %}
{% else %}
{% if params.T is defined %}
{% set TMP=params.T|int %}
{% else %}
{% set TMP=printer["gcode_macro m600cfg"].default_temp %}
{% endif %}
{% endif %}
{% if printer.extruder.temperature|int > TMP|int %}
M{printer["gcode_macro m600cfg"].output|int} Temperature set to {TMP}.
M104 S{TMP}
{% else %}
M{printer["gcode_macro m600cfg"].output|int} Heating to {TMP}
M109 S{TMP}
{% endif %}
##### THAT'S IT !
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment