Post processing script to find an replace Gcode commands
I am using compressed air instead of a dedicated hotend and part cooling fan on my Duet controlled printer running Reprap Firmware. The Airflow for part cooling is regulated by a ball valve that is actuated by a stepper motor.
Since it is not possible to map a stepper motor to a fan output in Reprap Firmware, I would like to replace all M106 S commands with G1 A (A is the dedicated axis for the valve stepper) to move the stepper in the correct position. So for example M106 S255 (Fan at 100%) is replaced with G1 A255 (Valve fully open)
I have tried adjusting some scripts I found without success. So a little help would be much appreciated. 🙂
I wrote a python Slic3r post-processing script to add a "bump" to fan speeds. It should be easy enough to modify to replace the fan commands. I haven't used it in a couple of years now, so I'm not sure how well it'll work with current versions of PrusaSlicer.
I use the regexp search/replace feature of Notepad++ - seems to work okay; but requires playing with regexp which can be a learning experience in itself (too many flavors, imo).
For example ^M73.*$\n finds and selects all lines with M73 in them.
Though, this technique won't allow programmatic replacement values: it is strictly 1 to 1 find / replace.
I tried running your script before making any changes. But it throws an error right away.
Post-processing script C:\Python\Python39\python.exe "C:\Python\Slic3r bump fan post processing script.py" on file C:\Users\maxbo\Desktop\3D-Print\Adapter.gcode failed.
Error code: 1
@maxgyver - Can you run that command from the command line? I believe Error code 1 indicates a permissions issue. You might try renaming the script to remove the spaces, as that can cause odd problems depending on OS. The script itself doesn't rely on any exotic libraries, but there's always the chance that something hasn't been installed. Are you able to run "hello world" level scripts?
The error persists after removing the spaces. The "hello world" scripts run without problems.
When running the script from console I get the following:
========================= RESTART: C:\Python\script.py =========================
Traceback (most recent call last):
File "C:\Python\script.py", line 6, in <module>
IndexError: list index out of range
Did you run it like this?
C:\Python\Python39\python.exe "C:\Python\Slic3r bump fan post processing script.py" "C:\Users\maxbo\Desktop\3D-Print\Adapter.gcode"
(fixing filenames where necessary)
It's stopping on a line before it gets into anything remotely tricky. Parsing command-line arguments is straightforward. You might try cutting it down to figure out what's going on with your python configuration:
#!/usr/bin/python import sys import re import os sourceFile=sys.argv print(sourceFile)