Post-processing Slic3r Prusa Edition G-Code¶
Post-processing Slic3r Prusa Edition g-code.
These notes are based on my experiences with the Prusa i3 Mk3 printer. If you are using a different printer, please verify the hardware details are same. These pages may be a bit rough as I revise them and add new material. Please check back regularly for updates.
There are some things that Slic3r Prusa Edition 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