• Čeština
  • Español
  • Italiano
  • Deutsch
  • Polski
  • Français

Post-processing scripts

This article is also available in following languages: 

There are some things that PrusaSlicer simply doesn’t do. However, using post-processing scripts you can automatically modify the generated G-code to do (almost) anything you want.

You can specify the path to the script in Print settings - Output options - Post-processing scripts.

Script setup

Post-processing scripts can be written in any programming language (Perl, Python, Ruby, Bash etc.). They just need to be recognized by your system as an executable and accept the path to the G-code file as the only argument.

If you want to run several scripts, put each script invocation into its own line.

Script execution

Each script will be passed the absolute path of a temporary G-code file that PrusaSlicer generates. This file is stored in a temporary folder on your drive (typically your fast system drive). The script is then executed to modify the G-code in place and the resulting G-code file is written to your selected target folder or sent to a print host, such as PrusaConnect or Octoprint.

Please note that the G-code viewer still visualizes G-code before post-processing.
PrusaSlicer passes all the slicing configuration to post processing scripts using the environment variables. Each variable is prefixed with "SLIC3R_" and the first variable name is capitalized. For example, the infill density is passed to the script as an environment variable "SLIC3R_Fill_density".
Two additional environment variables are passed to post processing scripts: The environment variable SLIC3R_PP_HOST provides the host specification, where "File" means copying the G-code to a local hard drive or removable media, while the other values ("PrusaLink", "Repetier", "SL1Host", "OctoPrint", "FlashAir", "Duet", "AstroBox" ...) specify the print host type the G-code will be sent to.
The environment variable SLIC3R_PP_OUTPUT_NAME contains the name of the G-code file including path (for SLIC3R_PP_HOST == "File") or a name that will be given to the file after it is uploaded to the host (PrusaLink, Octoprint ...)
The post-processing script may suggest a new output file name (likely based on SLIC3R_PP_OUTPUT_NAME) by saving it as a single line into a new "output name" temp file, for example to add time stamps or sequence numbers to the final G-codes.The "output name" file name is to be created by suffixing the input G-code file name with ".output_name". PrusaSlicer will read the new name of the file and handle it properly, for example, when sending it to Octoprint.

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

If path to executable or arguments contain spaces, these arguments need to be escaped using the escaping style common to the platform (shell escaping style on Linux and OSX, Windows command line escaping).



Adding counter to the file name example

Path to the final exported file (or its name for Octoprint)

env_slicer_pp_output_name = str(getenv('SLIC3R_PP_OUTPUT_NAME'))

Python script that modifies the output path

with open(sourcefile + '.output_name', mode='w', encoding='UTF-8') as fopen:
fopen.write(counter + '_' + env_slicer_pp_output_name)


Historical changes and breaking backward compatibility

Before version 2.4, PrusaSlicer used to execute the script on the final G-code exported to your desired target medium. Which was very often a removable drive, such as an SD card. SD cards are slow and wear out, so this was not ideal. There were also problems when sending the G-code to Octoprint. The new approach with the temporary file on your system drive prevents these problems and extends the functionality of post-processing scripts. However, it might break some of your existing scripts.


This documentation page includes some texts from the original Slic3r documentation and from Bob's Project Notebook.

Was this article helpful?


Please sign in before adding a comment.
Still have questions?

Still have questions?

If you have a question about something that isn't covered here, check out our additional resources.
And if that doesn't do the trick, you can send an inquiry to info@prusa3d.com or through the button below.