2.2.22. Post-processing PrusaSlicer G-Code
Todo
Post-processing PrusaSlicer g-code.
Note
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#!/usr/bin/python
2import sys
3import re
4import os
5
6sourceFile=sys.argv[1]
7
8# Read the ENTIRE g-code file into memory
9with open(sourceFile, "r") as f:
10 lines = f.readlines()
11
12destFile = re.sub('\.gcode$','',sourceFile)
13os.rename(sourceFile,destFile+".bumpfan.bak")
14destFile = re.sub('\.gcode$','',sourceFile)
15destFile = destFile + '.gcode'
16
17with open(destFile, "w") as of:
18 for lIndex in xrange(len(lines)):
19 oline = lines[lIndex]
20 # Parse gcode line
21 parts = oline.split(';', 1)
22 if len(parts) > 0:
23 # Parse command
24 command = parts[0].strip()
25
26 if command:
27 stringMatch = re.search ('^M106 S(.*)', command)
28 if stringMatch:
29 # Insert code to bump fan to max before fan speed commands
30 of.write('M106 S255\n')
31
32 # Write original line
33 of.write(oline)
34of.close()
35f.close()
Specify the path to the script
See also
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 projects@ttlexceeded.com.
Last updated 20190831