Post processing script to find an replace Gcode commands
 

Post processing script to find an replace Gcode commands  

  RSS
MaxGyver
(@maxgyver)
Active Member

Hey all,

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. 🙂

-Max

Posted : 13/05/2021 9:45 pm
bobstro
(@bobstro)
Illustrious Member

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.

My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 13/05/2021 10:31 pm
--
 --
(@)
Illustrious Member

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.

This post was modified 1 month ago by --
Posted : 14/05/2021 1:06 am
MaxGyver
(@maxgyver)
Active Member

@bobstro

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

-Max

Posted : 14/05/2021 3:03 pm
bobstro
(@bobstro)
Illustrious Member

@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?

 

My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 14/05/2021 3:11 pm
MaxGyver
(@maxgyver)
Active Member

@bobstro

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>
sourceFile=sys.argv[1]
IndexError: list index out of range
>>>

-Max

Posted : 14/05/2021 3:59 pm
bobstro
(@bobstro)
Illustrious Member

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[1]

print(sourceFile)


My notes and disclaimers on 3D printing and miscellaneous other tech projects
He is intelligent, but not experienced. His pattern indicates two dimensional thinking. -- Spock in Star Trek: The Wrath of Khan...
Posted : 14/05/2021 5:02 pm
Share:

Please Login or Register