1.2.21. Post-processing PrusaSlicer G-Code¶
Post-processing PrusaSlicer g-code.
These notes are based on my experiences with the Prusa i3 Mk3 and Artillery/Evnovo Sidewinder X1 printers. If you are using a different printer, please verify the hardware details are similar.
There are some things that PrusaSlicer simply doesn’t do. The ability to automatically modify gcode is provided through post-processing scripts. Scripts can be written in a variety of languages, but you are responsible for installing and configuring the programming language and support files on your system.
Once you’ve properly configured your programming language of choice, you can call a program to modify standard input and write it to another file. Here’s an example python script to briefly bump fan speeds to 100% whenever the fan is started.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
#!/usr/bin/python import sys import re import os sourceFile=sys.argv # Read the ENTIRE g-code file into memory with open(sourceFile, "r") as f: lines = f.readlines() destFile = re.sub('\.gcode$','',sourceFile) os.rename(sourceFile,destFile+".bumpfan.bak") destFile = re.sub('\.gcode$','',sourceFile) destFile = destFile + '.gcode' with open(destFile, "w") as of: for lIndex in xrange(len(lines)): oline = lines[lIndex] # Parse gcode line parts = oline.split(';', 1) if len(parts) > 0: # Parse command command = parts.strip() if command: stringMatch = re.search ('^M106 S(.*)', command) if stringMatch: # Insert code to bump fan to max before fan speed commands of.write('M106 S255\n') # Write original line of.write(oline) of.close() f.close()
Specify the path to the script
Contact and feedback
You can find me on the Prusa support forums or Reddit where I lurk in many of the 3D printing-related subreddits. I occasionally drop into the Official Prusa 3D discord server where I can be reached as bobstro (bobstro#9830). You can email me directly at firstname.lastname@example.org.
Last updated 20190831