Part 2: Anatomy of a Macro
Defining a macro.
Now that some core concepts are out of the way, we will make a common start
print macro that is called by the slicer when a print starts. It will move the
nozzle to the corner of the bed and draw a priming line.
In the config file we first need to define the macro. Macros are prefixed with
gcode_macro
followed by a space and then then name of the macro.
[gcode_macro start_print]
The next thing that is needed is the actual gcode to be executed. After the
macro declaration, we need to define a gcode:
section for the macro. Once the
gcode:
section has been added, we can put the gcode into the template.
The actual gcode commands must be indented otherwise the config file will fail
to load. You can see in this macro, each line has been commented so that it’s
purpose is understood.
[gcode_macro start_print]
gcode:
G92 E0 # Reset Extruder
G1 Z2.0 F3000 # Move Z Axis to travel height
G1 X0.1 Y20 Z0.2 F5000.0 # Move to start position
G1 X0.1 Y200.0 Z0.2 F1500.0 E15 # Draw the first line
G1 X0.4 Y200.0 Z0.2 F5000.0 # Move to side a little
G1 X0.4 Y20 Z0.3 F1500.0 E30 # Draw the second line
G92 E0 # Reset Extruder
G1 Z2.0 F3000 # Move Z Axis up to travel height
We can then call the macro at any time from the terminal or from a gcode file
by simply adding start_print
. This could also be included in the slicer’s
start-gcode section so that it is called when the machine starts executing the
file. When the file is being read by Klipper or Octoprint or whatever, it will
come to the line start_print
and that command will be substituted for the
set of commands in the macro.