Skip to main content

Site Navigation

Your Account

Choose Language


A work in progress page for useful gcode macros.


RepRapFirmware allows for gcode sequences, called macros, to be stored on the SD card. these macros can then be called by entering :

M98 P"mymacro.g"

Macros can be called from any source of gcode: the console, from a gcode printing off the SD card, from the PanelDue and from another user or system macro. DuetWebControl makes it easy to upload, edit and create new macros.

Macros also allow for naming gcodes with easier to remember names. For example you can create a Macro for "Allow Cold Extrude" to call M302 P1.

The macro folder can divided into sub directories to more easily organise your macros by type.

Block Image

For more information see Setting up macro files for common tasks

System files are also effectively macros, for example homing files are a sequence of gcodes to run the specific homing sequence for a specific printer type. See here for information on using tool change macros

The RepRap wikialso contains a page of useful macros:

RepRapFirmware configurator

RepRapFirmware configurator will produce appropriate system macros for most basic printer types. These are generally a good start point.


There is a github repository here for macros.

It is a work in progress. Please submit pull requests or comment on the forum if you have example macros to share.

Printer management

Start and end gcodes

Macros can be used to complement printer "start gcode" and "end gcode", for example if you have different printers, with different start and ends sequences, but you want to use the same sliced gcode, you could use

M98 P" startprint.g"

Filament management

see Filaments, specific load and unload macros can be defined by filament type.

Calibration and Tuning

Calibration and tuning printer settings often requires repeating the same steps repeatedly, changing one variable at a time. Macros can help automate this.

(from forum user Phaedrux)

As set of simple short cuts for various pressure advance settings:

  • Turn Off Pressure Advance
  • Report Pressure Advance Value
  • Set Pressure advance to between 0.1 and 0.01 in 0.01 steps

Other Macros


It is possible to use macros to make the PanelDue beeper play simple tunes by using the M300 (play beep) gcode and the G4 (dwell) gcodes.

System Macros

RepRapFirmware uses gcode files to script many user configurable printer actions. The use of these system macros and opposed to hard coding the functionality is one the reasons RepRapFirmware is so flexible. It is recommended to start with a configuration from the RepRapFirmware configurator or a known good configuration as a start point.

Note, all these macros are in /sys/ on the SD card unless otherwise noted


Homing macros depend on the type of printer you are using. See:

Bed probing

Deploying and retracting the probe

If you have a z probe that must be deployed before probing and retracted afterwards use deployprobe.g and retractprobe.g to call the appropriate deploy and retract commands. These are called by M401 - Deploy z probe, M402 - Retract z probe.

Note: If you do not have a Z probe that needs to deploy or retract you must not have these files in the /sys/ directory

Delta calibration

bed.g is used as part of delta calibration.

Tool change

There are normally three specified tool change macros (any of which can contain no commands if desired) that execute in this order:

  • Actions to do with the old tool before it is released - macro name: tfreeN.g where N is the tool number;
  • Actions to do with the new tool before it is selected - macro name: tpreN.g where N is the tool number;
  • Actions to do with the new tool after it is selected - macro name: tpostN.g where N is the tool number.

See Selecting a tool for more details.

Start, pause, stop and power fail

  • start.g is run when you start a print from SD card.
  • pause.g is run when you pause a print.
  • resume.g is run when you resume a print.
  • cancel.g is optional, but if present is run when you cancel a paused print.
  • stop.g is optional, but if present is run when a print finishes normally with an M0 command at the end of the print job.
  • sleep.g If M1 is issued the firmware finishes any moves left in its buffer, then shuts down, the macro file sleep.g is run before all heaters and drives are turned off.

The Duet can be configured to detect a power failure and store the current state once the power returns if a user wants to resume the print resurrect-prologue.g is run that would contain user commands to home the printer etc before resuming.


M581 can be used to setup the external triggers (switches etc). These triggers carry out actions defined in trigger#.g

3D scanner control

M752 runs two macros before and after a 3d scan: before the SCAN command is sent to the scanner, the macro file scan_pre.g is executed and when the scan has finished, the macro file scan_post.g is run.


Add Comment

View Statistics:

Past 24 Hours: 22

Past 7 Days: 94

Past 30 Days: 359

All Time: 4,204