Using START_PRINT and END_PRINT Macros

Using START_PRINT and END_PRINT Macros

Rationale

The START_PRINT and END_PRINT macros are optional but can be used to standardize the printer’s initialization process across different machines. They provide more control over the initialization procedure, which can be particularly useful for printers that require more complex initialization steps.

The idea behind them is simple:

  • The slicers offer an abundance of variables, e.g. the extruder / bed temperature of the first layer, Z-offsets, etc
  • These variables are filled when slicing a model with the respective values from the filament or from other slicer setting
  • Via the Klipper macro system such variables can be passed into Klipper, e.g. to prepare the print, heat up the system etc.

The Macros

The sample-macros.cfg provides basic examples for both START_PRINT and END_PRINT macros. Additional information are also included in the official documentation.

How it works

[gcode_macro START_PRINT]
gcode:
    {% set BED_TEMPERATURE = params.BED_TEMP|default(60)|float %}
    {% set EXTRUDER_TEMPERATURE = params.EXTRUDER_TEMP|default(190)|float %}
    ...
    # Wait for bed to reach temperature
    M190 S{BED_TEMPERATURE}

The relevant logic is in the first few lines of the macro.

  • The params.XXX statements declare that the macro is expecting to be called with the respective XXX parameter, e.g. START_PRINT BED_TEMP=60.0
  • The default(YY) statements will set the respective value if the macro is not called with this parameter
  • The float declares the data type, e.g. float here for a decimal number, that is expected as input
  • The set ZZZ declares the variable that is used within the macro to actually do something with the passed information, e.g. the M190 S{BED_TEMP}. The { ... } curly brackets are mandatory to access the variable.

Slicer Variables

What kind of variables a slicer offers, and how they are named, varies from slicer to slicer. Following is an overview of the most popular ones:

Most Relevant Variables

Slicer BED_TEMP EXTRUDER_TEMP
Orca {bed_temperature_initial_layer[current_extruder]} {nozzle_temperature_initial_layer[current_extruder]}
Prusa {first_layer_bed_temperature[current_extruder]} {first_layer_temperature[current_extruder]}
Cura {material_bed_temperature_layer_0} {material_print_temperature_layer_0}

Setting Up The Slicer

Where the respective macro calls need to be put depends on the slicer. Some slicers even offer two locations where this is possible:

  • The printer / machine settings as a “global” setting
  • The filament settings as a filament specific setting. This has the advantage that potentially additional settings, e.g. a filament specific Z-offset, could be passed.

Only one place shall be used, or it will lead to undefined / unwanted behavior.

For the popular slicers the locations are:

  • Orca:
    • Printer Preset → Machine G-code
    • Filament Preset → Advanced
  • Prusa:
    • Printer Settings → Custom G-code
    • Filament Settings → Custom G-code
  • Cura:
    • Settings → Printer → Manage Printers → Machine Settings
    • Cura does not support filament specific G-codes

When using the macros from the documentation example above, the relevant calls are:

Slicer Calling G-code
Orca START_PRINT BED_TEMP={bed_temperature_initial_layer[current_extruder]} EXTRUDER_TEMP={nozzle_temperature_initial_layer[current_extruder]}
Prusa START_PRINT BED_TEMP={first_layer_bed_temperature[current_extruder]} EXTRUDER_TEMP={first_layer_temperature[current_extruder]}
Cura START_PRINT BED_TEMP={material_bed_temperature_layer_0} EXTRUDER_TEMP={material_print_temperature_layer_0}

Example for the Prusa slicer:

Note:
There must be no line-breaks in these macro calls from within the slicer.

Validating The Setup

After configuring the slicer, it makes sense to validate that things are working like intended.
This can easily be done by slicing some model and then opening the resulting G-code in an editor.

After some initial blurb, a call similar to:

START_PRINT BED_TEMP=105 EXTRUDER_TEMP=270

needs to appear, with the variables being expanded into the actually requested temperatures.

6 Likes