By utilizing post-processing scripts, you can automatically customize the generated G-code to achieve virtually any desired outcome.
You can specify the location of your script in Print settings - Output options - Post-processing scripts.
Post-processing scripts can be crafted in any programming language, including Perl, Python, Ruby, Bash, and more. The only requirement is that your system recognizes the script as executable and accepts the path to the G-code file as its sole argument.
If you wish to run multiple scripts, simply include each script invocation on a separate line.
Each script will receive the absolute path of a temporary G-code file generated by QIDISlicer. This file is temporarily stored on your system's fast drive. The script will then execute, modifying the G-code in place, and the resultant G-code file will be written to your chosen destination folder or sent to a print host.
The G-code viewer displays the code before post-processing.
QIDISlicer conveys all slicing configurations to post-processing scripts via environment variables. Each variable is prefixed with "SLIC3R_" and follows a camel-case naming convention. For instance, the infill density is passed as "SLIC3R_Fill_density".
Additionally, two specific environment variables are provided:
SLIC3R_PP_HOST: Specifies the destination host, where "File" indicates copying the G-code to a local drive or removable media, while other values (e.g., "PrusaLink", "Repetier", "SL1Host", "OctoPrint", "FlashAir", "Duet", "AstroBox", etc.) designate the print host type.
SLIC3R_PP_OUTPUT_NAME: Contains the G-code file name, including the path (for SLIC3R_PP_HOST == "File") or the name assigned to the file upon uploading to the host.
You can incorporate parameters into your script as follows:
/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 the executable path or arguments contain spaces, ensure you use the appropriate escaping style for your platform (shell escaping on Linux and OSX, Windows command line escaping).
Examples:
env_slicer_pp_output_name = str(getenv('SLIC3R_PP_OUTPUT_NAME'))
with open(sourcefile + '.output_name', mode='w', encoding='UTF-8') as fopen:
fopen.write(counter + '_' + env_slicer_pp_output_name)