Skip to content

Instantly share code, notes, and snippets.

@rootiest
Last active April 22, 2024 18:52
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save rootiest/409089502bbea36c750987871667132b to your computer and use it in GitHub Desktop.
Save rootiest/409089502bbea36c750987871667132b to your computer and use it in GitHub Desktop.
SuperSlicer Super Start for Klipper
[gcode_macro PREP_PRINT]
description: Loads and starts the print
variable_x_max: 0
variable_y_max: 0
variable_z_max: 0
variable_nozzle: 0
variable_fila_dia: 0
variable_bed_temp: 0
variable_extruder_temp: 0
variable_chamber_temp: 0
variable_layer_count: 0
variable_tool_changes: 0
variable_cur_layer: 0
variable_num_layers: 0
variable_layer_z: 0
gcode:
M117 Print intializing...
#Get Printer built volume dimensions
{% set X_MAX = printer.toolhead.axis_maximum.x|default(100)|float %}
{% set Y_MAX = printer.toolhead.axis_maximum.y|default(100)|float %}
{% set Z_MAX = printer.toolhead.axis_maximum.z|default(100)|float %}
#Get Nozzle diameter and filament width for conditioning
{% set NOZZLE = printer.extruder.nozzle_diameter|default(0.4)|float %}
{% set FILADIA = printer.extruder.filament_diameter|default(1.75)|float %}
#Set Start coordinates of priming lines
{% set X_START = 10.0|default(10.0)|float %}
{% set Y_START = 20.0|default(20.0)|float %}
#Calculate Primer line extrusion volume and filament length
{% set PRIMER_WIDTH = 0.75 * NOZZLE %}
{% set PRIMER_HEIGHT = 0.70 * NOZZLE %}
{% set PRIMER_SECT = PRIMER_WIDTH * PRIMER_HEIGHT %}
{% set PRIMER_VOL = PRIMER_SECT * (X_MAX - 3 * X_START) %}
{% set FILA_SECT = 3.1415 * ( FILADIA / 2.0)**2 %}
{% set FILA_LENGTH = 1.55 * PRIMER_VOL / FILA_SECT %}
{% set FILAMENT_TYPE = params.FILAMENT|default(PLA)|string %}
#Get Bed, Extruder, and Chamber temperatures from Slicer GCode
{% set BED_TEMP = params.BED|default(60)|float %}
{% set EXTRUDER_TEMP = params.EXTRUDER|default(210)|float %}
{% set CHAMBER_TEMP = params.CHAMBER|default(50)|float %}
# Get Number of Layers
{% set NUM_LAYERS = params.COUNT|default(0)|float %}
{% set CUR_LAYER = params.NUM|default(0)|float + 1 %}
# Get Number of Tool Changes Required
{% set TOOL_CHANGES = params.TOOLS|default(0)|float %}
# Save print configuration specs for later use
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=x_max VALUE={X_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=y_max VALUE={Y_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=z_max VALUE={Z_MAX}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=nozzle VALUE={NOZZLE}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=fila_dia VALUE={FILADIA}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=bed_temp VALUE={BED_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=extruder_temp VALUE={EXTRUDER_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=chamber_temp VALUE={CHAMBER_TEMP}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=cur_layer VALUE={CUR_LAYER}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=num_layers VALUE={NUM_LAYERS}
SET_GCODE_VARIABLE MACRO=PREP_PRINT VARIABLE=tool_changes VALUE={TOOL_CHANGES}
# Turn on the lights!
#WLED_ON PRESET=1
# Begin preheating and prepping for print
G90 ; use absolute coordinates
M83 ; extruder relative mode
M117 Preheating bed for homing...
M104 S150 ; set temporary nozzle temp to prevent oozing during homing and auto bed leveling
G4 S10 ; allow partial nozzle warmup
M190 S{BED_TEMP} ; set final bed temp
M117 Homing all axis...
G28 ; home all axis
BED_MESH_PROFILE LOAD="default"
G1 Z50 F240
G1 X2 Y10 F3000
M117 Waiting for temperatures to stabilize...
M104 S{EXTRUDER_TEMP} ; set final nozzle temp
M190 S{BED_TEMP} ; wait for bed temp to stabilize
M109 S{EXTRUDER_TEMP} ; wait for nozzle temp to stabilize
WIPE_LINE
M117 Print Started
[include variables.cfg]
[include WIPE_LINE.cfg]
[include PREP_PRINT.cfg]
prep_print EXTRUDER={first_layer_temperature[initial_extruder] + extruder_temperature_offset[initial_extruder]} BED={first_layer_bed_temperature} CHAMBER={chamber_temperature} FILAMENT={filament_type} COUNT={total_layer_count} TOOLS={total_toolchanges} NUM=1;Load print settings
[save_variables]
filename: ~/klipper_config/variables.cfg
[gcode_macro SAVE_AT_END]
variable_save: 0
gcode:
SET_GCODE_VARIABLE MACRO=SAVE_AT_END VARIABLE=save VALUE=1
[gcode_macro SAVE_IF_SET]
gcode:
{% if printer["gcode_macro SAVE_AT_END"].save == 1 %}
SAVE_CONFIG
{% endif %}
[gcode_macro INITIALIZE_VARIABLE]
gcode:
{% if 'VARIABLE' not in params %}
{action_respond_info("Missing VARIABLE parameter")}
{% elif 'VALUE' not in params %}
{action_respond_info("Missing VALUE parameter")}
{% else %}
{% set svv = printer.save_variables.variables %}
{% if params.VARIABLE not in svv %}
{% set escaped = params.VALUE|replace("\"", "\\\"") %}
SAVE_VARIABLE VARIABLE={params.VARIABLE} VALUE="{escaped}"
{% endif %}
{% endif %}
[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 Y20 Z5 F3000
G1 Z{z} F3000
G1 X10 Y150 F1500 E10.83
G1 X{ n + 10.0 } F5000
G1 Y22 F1500 E21.5
G1 Y20 F5000
RESTORE_GCODE_STATE NAME=WIPE_LINE_state MOVE=0
{% endif %}
@rootiest
Copy link
Author

This macro package will collect print configuration parameters from the Slicer and store them in variables for other macros to make use of.

It also runs the pre-print steps to:

Preheat the bed and chamber (and partially preheat the nozzle)
Home the axis (after bed is preheated)
Load the default mesh
Fully preheat the nozzle, bed, and chamber
Lay a wipe line to prime the nozzle (using specs loaded from slicer)
Start the print

My M73 with layer progress package uses PREP_PRINT to obtain the initial layer stats and then to store the changing layer progress variables throughout the print.

@dhruvinsh
Copy link

dhruvinsh commented Jan 14, 2023

Thank you. This will come in handy for my Elegoo Neptune 2s klipper build. I am currently processing some of the info that I don't know but remaining stuff are useful.

  • What is the reason for this M117 Print intializing... printouts.
  • What is the use of M73?
  • In WIPE_LINE, why are you checking for homed_axes? Like if you want to run it manually?
  • also WIPE_LINE might not get the z and n value, they will be using default values only.

@rootiest
Copy link
Author

rootiest commented Jan 14, 2023

What is the reason for this M117 Print intializing... printouts.

M117 is just used to send status messages to the display.

You can add the following to your printer.cfg: [respond] and then replace any M117 with M118 to have it output them to the console instead.

What is the use of M73?

M73 is used to update the print progress percentage. My M73 layer progress macro isn't really necessary in Klipper anymore as there is now a native way to track layer progress with SET_PRINT_STATS_INFO.

In WIPE_LINE, why are you checking for homed_axes? Like if you want to run it manually?
Sure, manually, or whatever. It's just sanity checks to prevent it from trying to print something when unhomed or below min_extrude_temp.

FYI:

This gist is quite old so some of it is outdated.

In particular, the syntax of the SuperSlicer start gcode has changed, and will probably need to be changed here as well if you wanted to use this code.

Check out my guide here to see the latest syntax for the Start Gcode of your preferred slicer.

Edit: Scratch that. PrusaSlicer changed, not SS.

@rootiest
Copy link
Author

rootiest commented Jan 14, 2023

If you want a very early preview (probably not working properly yet) of a more advanced start_print macro:

I have been working on a project that will implement extremely customizable and functional macros for a lot of common tasks in Klipper.

It goes far beyond just a START_PRINT macro, but the idea is that it's designed in a way that you can enable or disable any function you want just by changing some configuration variables and hopefully it will be a good solution for anyone who wants to really take advantage of macros without writing their own.

It's still a ways off from being complete, but if you are interested you can check it out here.

The documentation is very much incomplete as well. This is a work in progress so it's going to be changing/breaking regularly until it's completed.

In other words: you probably shouldn't use it in its current state, except maybe for inspiration.

@dhruvinsh
Copy link

Thank you for the update. I will go through the repo.

@rootiest
Copy link
Author

No problem, let me know how it works out!

@Zubzero922
Copy link

Will this work with any printer? I have an Ender 3 Max connected with klipper and pruca?

@Oddly
Copy link

Oddly commented Sep 18, 2023

Got this to work with an Ender 3 S1 Pro, thanks for the effort!

@rootiest
Copy link
Author

Will this work with any printer? I have an Ender 3 Max connected with klipper and pruca?

Hey sorry I missed this. Yeah it should work with any printer really.

As far as PrusaSlicer, you may need to set a value for the CHAMBER= manually since PS doesn't support chamber temperature.
There may be some other minor tweaks necessary to the variable names, but for the most part PrusaSlicer and SuperSlicer match up.

@rootiest
Copy link
Author

Got this to work with an Ender 3 S1 Pro, thanks for the effort!

Awesome, glad you like it!

@Zubzero922
Copy link

Will this work with any printer? I have an Ender 3 Max connected with klipper and pruca?

Hey sorry I missed this. Yeah it should work with any printer really.

As far as PrusaSlicer, you may need to set a value for the CHAMBER= manually since PS doesn't support chamber temperature. There may be some other minor tweaks necessary to the variable names, but for the most part PrusaSlicer and SuperSlicer match up.

Thx I will try this 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment