Slic3r Manual

There may be times when the G-Code generated by Slic3r has to be tweaked or modified after it has been created. For this reason there exists the ability to run arbitrary scripts as part of the final steps in the slicing process.

Example scripts can be found in the GitHub repository or in the RepRap forum.

Note: post-processing scripts can be written in any language (Perl, Python, Ruby, Bash etc.). They just need to be executable and to accept the path to the G-code file as the only argument.

In the Output options section of the Print Settings tab lies the Post-processing scripts option. The absolute path to each script can be added, separated by semicolons. Each scripts should be recognised by the host system, and be executable.

Post-processing script option.

Post-processing script option.

Each script will be passed the absolute path of the G-code file that Slic3r generates. The script will need to modify it in-place; alternatively it can output the new G-code to a temporary file and then overwrite the original one with it.

All Slic3r configuration options are made available to the scripts by way of environment variables. These all begin with SLIC3R_, for example SLIC3R_LAYER_HEIGHT. The following script would leave the G-code unmodified and just write out all Slic3r options to standard output:

echo "Post-processing G-code file: $*"
env | grep ^SLIC3R

Post-Processing Script Parameters

You can use parameters with your script as such:


/path/to/executable becomes /path/to/executable with the arg outputfilename.gcode

/path/to/executable -arg -arg2 becomes /path/to/executable with args -arg, -arg2, and outputfilename.gcode

/path/to/executable! with! spaces -arg -arg2 becomes /path/to/executable with spaces with args -arg, -arg2, and outputfilename.gcode

/path/to/executable!! -arg -arg2 becomes /path/to/executable! with args -arg, -arg2, and outputfilename.gcode

/path/to/executable option! with! spaces becomes /path/to/executable with args option with spaces and outputfilename.gcode

Perl example

Perl's in-place mode (perl -i) makes it easy to modify the contents of the G-Code file, without having to copy, edit, then replace the original. The following example will simply output the contents to standard output:

#!/usr/bin/perl -i
use strict;
use warnings;

while (<>) {
     # modify $_ here before printing

If you are getting a can't do inplace edit without backup error when specifying the post-process script, try adding $^I = '.bak'; before the while loop. This will create a backup file of the generated G-Code file. Windows does not like to have two scripts creating and/or accessing a single file at once, so a backup is needed.

Python example


To use a Python post-processing script with Windows, you'll need to adjust the paths like this:

C:\Program! Files! (x86)\Python37-32\python.exe c:\dev\SCPP\ -o --au "John Doe"

Note the ! before all white-spaces! Make sure you adjust the path to your script as well. Yes, you can save your G-Code file to somewhere with spaces in it's path.

Your script needs to accept at least one parameter: The filename of your G-Code file. -o and --au "John Doe" are optional parameters. The filename, of your G-Code, will be added to the end of this string.

Python.exe will then run your script with the specified parameters.

This will just output the filename submitted by Slic3r:

import sys
print ('This is the name of your G-Code file: {0}'.format(sys.argv[1]))

sys.argv[0] is the script