Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Klipper Custom G-Code Macros - Updated & Complete
- #
- # In your slicer, set your start G-code to:
- # START_PRINT BED_TEMP=[first_layer_bed_temperature] EXTRUDER_TEMP=[first_layer_temperature]
- #
- # And your end G-code to:
- # END_PRINT
- #
- # --- 1. Slicer Entry Point Macros ---
- # These are the simple macros you call from your slicer.
- [gcode_macro START_PRINT]
- description: The primary macro called by your slicer to start a print
- gcode:
- # Pass all slicer parameters to the main start logic
- _PRINT_START_LOGIC BED_TEMP={params.BED_TEMP} EXTRUDER_TEMP={params.EXTRUDER_TEMP}
- [gcode_macro END_PRINT]
- description: The primary macro called by your slicer to end a print
- gcode:
- _PRINT_END_LOGIC
- # --- 2. Core Print Workflows ---
- # These macros contain the detailed logic for starting and ending a print.
- [gcode_macro _PRINT_START_LOGIC]
- gcode:
- # Parameters passed from START_PRINT
- {% set BED_TEMP = params.BED_TEMP|default(60)|float %}
- {% set EXTRUDER_TEMP = params.EXTRUDER|default(210)|float %}
- {% set x_wait = printer.toolhead.axis_maximum.x|float / 2 %}
- {% set y_wait = printer.toolhead.axis_maximum.y|float / 2 %}
- M117 Homing...
- _CG28 ; Conditional home
- M117 Heating Bed to {BED_TEMP}C...
- M190 S{BED_TEMP}
- M117 Heating Hotend to 150C for probing...
- M109 S150
- M117 Creating Bed Mesh...
- BED_MESH_CALIBRATE ADAPTIVE=1
- M117 Heating Hotend to {EXTRUDER_TEMP}C...
- G1 X{x_wait} Y{y_wait} Z15 F9000
- M109 S{EXTRUDER_TEMP}
- M117 Purging...
- LINE_PURGE ; This is a generic purge line macro defined below
- M117 Print Starting!
- [gcode_macro _PRINT_END_LOGIC]
- gcode:
- # Get printer boundaries
- {% set max_x = printer.configfile.config["stepper_x"]["position_max"]|float %}
- {% set max_y = printer.configfile.config["stepper_y"]["position_max"]|float %}
- M400 ; Wait for buffer to clear
- G92 E0 ; Zero the extruder
- G1 E-4.0 F3600 ; Retract filament
- # Move nozzle up and away
- G90 ; Absolute positioning
- G0 X{max_x / 2} Y{max_y - 10} F3600 ; Move to back-center
- TURN_OFF_HEATERS
- M107 ; Turn off part cooling fan
- M84 ; Disable motors
- M117 Print Finished!
- # --- 3. Pause / Resume / Cancel ---
- # These are essential for interacting with the print from Mainsail.
- [gcode_macro PAUSE]
- description: Pause the active print
- rename_existing: PAUSE_BASE
- gcode:
- PAUSE_BASE
- _TOOLHEAD_PARK_PAUSE_CANCEL
- [gcode_macro RESUME]
- description: Resume the active print
- rename_existing: RESUME_BASE
- gcode:
- M109 S{printer.motion_queue.extruder_temp} ; Restore extruder temperature
- RESUME_BASE
- [gcode_macro CANCEL_PRINT]
- description: Cancel the active print
- rename_existing: CANCEL_PRINT_BASE
- gcode:
- TURN_OFF_HEATERS
- _TOOLHEAD_PARK_PAUSE_CANCEL
- CLEAR_PAUSE
- SDCARD_RESET_FILE
- BASE_CANCEL
- [gcode_macro _TOOLHEAD_PARK_PAUSE_CANCEL]
- description: Helper macro to park the toolhead during a pause or cancel
- gcode:
- SAVE_GCODE_STATE NAME=PAUSE_PARK
- G90
- G1 Z{printer.toolhead.position.z + 5} F19000
- G1 X{printer.toolhead.axis_maximum.x / 2} Y{printer.toolhead.axis_minimum.y + 5} F19000
- RESTORE_GCODE_STATE NAME=PAUSE_PARK
- # --- 4. Filament Handling ---
- # Macros for loading, unloading, and changing filament mid-print.
- [gcode_macro M600]
- description: Filament change command
- gcode:
- PAUSE
- M117 Filament Change
- M118 Unload filament, then insert new filament.
- M118 Once ready, click RESUME.
- [gcode_macro LOAD_FILAMENT]
- description: Load filament into the extruder
- gcode:
- {% set TEMP = params.TEMP|default(210)|int %}
- M109 S{TEMP}
- M117 Loading Filament...
- G91
- G1 E50 F300
- G1 E40 F100
- G90
- M117 Filament Loaded
- [gcode_macro UNLOAD_FILAMENT]
- description: Unload filament from the extruder
- gcode:
- {% set TEMP = params.TEMP|default(210)|int %}
- M109 S{TEMP}
- M117 Unloading Filament...
- G91
- G1 E5 F300
- G1 E-10 F2000
- G1 E-70 F1500
- G90
- M117 Filament Unloaded
- # --- 5. Utility & Compatibility Macros ---
- # These are helper macros and G-code overrides.
- [gcode_macro _CG28]
- description: Conditional G28 (home only if needed)
- gcode:
- {% if "xyz" not in printer.toolhead.homed_axes %}
- G28
- {% endif %}
- [gcode_macro G29]
- description: Override G29 to run a full adaptive bed mesh
- gcode:
- BED_MESH_CLEAR
- BED_MESH_CALIBRATE ADAPTIVE=1
- [gcode_macro LINE_PURGE]
- description: A generic purge line macro
- gcode:
- G92 E0 ; Reset Extruder
- G1 Z1.0 F3000 ; Move Z up
- G1 X5 Y5 F5000 ; Move to start position
- G1 Z0.3 F5000 ; Move Z down
- G1 F2000
- G1 X100 E20 ; Draw the first line
- G1 X100 Y5.3 ; Move to side
- G1 X5 E20 ; Draw the second line
- G92 E0 ; Reset Extruder
- G1 Z1.0 F3000 ; Move Z up
- # --- 6. Diagnostic Macros ---
- # Macros used for tuning and testing.
- [gcode_macro TEST_SPEED]
- description: Test for max speed and acceleration parameters.
- gcode:
- # Parameters
- {% set speed = params.SPEED|default(printer.configfile.settings.printer.max_velocity)|int %}
- {% set iterations = params.ITERATIONS|default(5)|int %}
- {% set accel = params.ACCEL|default(printer.configfile.settings.printer.max_accel)|int %}
- {% set bound = params.BOUND|default(20)|int %}
- # Axis Boundaries
- {% set x_min = printer.toolhead.axis_minimum.x + bound %}
- {% set x_max = printer.toolhead.axis_maximum.x - bound %}
- {% set y_min = printer.toolhead.axis_minimum.y + bound %}
- {% set y_max = printer.toolhead.axis_maximum.y - bound %}
- SAVE_GCODE_STATE NAME=TEST_SPEED
- { action_respond_info("TEST_SPEED: starting %d iterations at speed %d, accel %d" % (iterations, speed, accel)) }
- G28
- G0 X{x_min} Y{y_min} Z{bound + 10} F{speed*60}
- SET_VELOCITY_LIMIT VELOCITY={speed} ACCEL={accel}
- {% for i in range(iterations) %}
- G0 X{x_min} Y{y_min} F{speed*60}
- G0 X{x_max} Y{y_max} F{speed*60}
- G0 X{x_max} Y{y_min} F{speed*60}
- G0 X{x_min} Y{y_max} F{speed*60}
- {% endfor %}
- SET_VELOCITY_LIMIT VELOCITY={printer.configfile.settings.printer.max_velocity} ACCEL={printer.configfile.settings.printer.max_accel}
- G28
- RESTORE_GCODE_STATE NAME=TEST_SPEED
- # --- Custom Utility Macros ---
- [gcode_macro HEAT_BED_FOR_TIME]
- gcode:
- # Announce the start of the process
- M117 Homing...
- # Home all three axes
- G28
- # Announce the next step
- M117 Lifting gantry...
- # Set to absolute positioning and lift gantry to 200mm
- G90
- G1 Z200 F3000
- # Get parameters or use defaults
- {% set T = params.TEMP|default(60)|int %}
- {% set M = params.TIME|default(30)|int %}
- # Announce heating cycle and set bed temperature
- M117 Heating bed to {T}C for {M} mins.
- SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={T}
- # Wait for the specified time in minutes
- G4 P{M * 60000}
- # Turn off bed heater and announce completion
- SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET=0
- M117 Bed heating complete.
Advertisement
Add Comment
Please, Sign In to add comment