Perl Post Processing - strip T commands for a message and M600
 
Notifications
Clear all

[Solved] Perl Post Processing - strip T commands for a message and M600  

  RSS
Jacotheron
(@jacotheron)
New Member
Perl Post Processing - strip T commands for a message and M600

I am using PrusaSlicer with a bunch of printers running Deut3D mainboards (all of these printers have single extruders/hotends). I have previously (with S3D and a lot of manual work, created prints with multiple colors/materials on the same layer) - I am trying to do it again with PrusaSlicer and less work.

Defining more extruders in PS is simple, and so far works, but it generates the T commands, which needs to be removed (while it is possible to define extruders in RRF with the same hardware, which will work for this, it clutters the PanelDue and DWC interfaces). So to make it simple, I want to post-process the files from PS.

I have created a Perl post script that does exactly what I need (I have tested it by calling perl manually, with this script and providing the filename to process):

#!/usr/bin/perl -i -p
#
# Remove all toolchange commands (and T# arguments) from gcode.

# use strict;
# use warnings;

my $print_have_started = 0;
# read stdin and any/all files passed as parameters one line at a time
while (<>) {
     if (not /^T[0-9]+/) { #this is the standard option for each line, that is not a tool change
         s/\s*(T[0-9]+)//; #this will strip out tool change mid of lines - I am not going to cover this
         print; #output the line
     } else {
         if(/^T0/ && $print_have_started == 0){
             print;
         }else{
             $print_have_started = 1; #only once we get a T1, should we start the stripping
             s/^T([0-9]+)/M291 R"Tool Change" P"Tool #$1" S1 T30\nM600/; #match a toolchange and insert message and M600
             print; #output the line
         }
     }
}

Ok, in short, the above loops through all lines, and when it finds a T that is not T0, it starts to replace them (even T0 commands) with 2 lines: 1st line: M291, which displays a message on the screens (PanelDue and DWC showing which tool is next, to easily identify the filament I need to supply); and the 2nd line is the M600 command that actually assists in the filament change. The script takes the file as STDIN.

For simple single extruder prints, this post will do nothing, and only when needed do its thing.

The issue I am having, is that when I run it from PrusaSlicer, I get an error code 25. Full message: "Post-processing script scripts\strip-toolchange.pl on file <desktoppath>\dual-test5.gcode failed. Error code: 25"

When supplying it with a wrong path to the script, it gives different error etc, but I can't get it to function correctly (I even swapped out the script with another one, same error). I fixed the missing perl option by extracting the perl-5.24.0-for-Slic3rPE to PrusaSlicer (do I need a different one).

I am wondering how the command is generated to execute the script, as it may be causing the issue. In my tests it was simply: perl.exe <path to script>.pl <path to file>

Best Answer by Jacotheron:

In the end I went for a Pythoin script, which at first had its own issues through PrusaSlicer ( https://github.com/prusa3d/PrusaSlicer/issues/4644) which was solved when I read the bottom at https://manual.slic3r.org/advanced/post-processing (basically for Python, you need to provide the path to Python.exe, and this path should not have spaces, or if it does, the spaces should be prepended by a "!" -> not enclosing the whole path in quotes).

Posted : 17/08/2020 6:40 pm
Jacotheron
(@jacotheron)
New Member
Topic starter answered:
RE: Perl Post Processing - strip T commands for a message and M600

In the end I went for a Pythoin script, which at first had its own issues through PrusaSlicer ( https://github.com/prusa3d/PrusaSlicer/issues/4644) which was solved when I read the bottom at https://manual.slic3r.org/advanced/post-processing (basically for Python, you need to provide the path to Python.exe, and this path should not have spaces, or if it does, the spaces should be prepended by a "!" -> not enclosing the whole path in quotes).

Posted : 20/08/2020 8:52 am
Share: