Welcome! Log In Create A New Profile

Advanced

Post-processing script

Posted by PierreYves.Pepin 
Post-processing script
April 09, 2014 03:26PM
Hey, I'm currently designing a SLA 3D printer (http://forums.reprap.org/read.php?4,316211). I'm running my laser with the servo output on the RAMPS. To power on the laser, I use M42 P4 S255 command and to power it off, I use M42 P4 S0. I'd like to have a post-processing script that would do the following.

- Add a M42 P4 S255 commande after each line containing G1 E0.01000
- Replace all retracting command lines (G1 E-0.01000) by M42 P4 S0

Example of a Gcode

G21 ; set units to millimeters
G28 ; home all axes
G1 Z5 F5000 ; lift nozzle
G90 ; use absolute coordinates
M83 ; use relative distances for extrusion
G1 F1800.000 E-0.01000 // Replace that whole line by M42 P4 S0
G1 Z0.200 F7800.000
G1 X60.475 Y22.012 F7800.000
G1 E0.01000 F1800.000
M42 P4 S255 // This line added after the script see E0.01000 term
G1 X62.513 Y22.012 E0.01650 F1200.000
G1 X62.513 Y31.008 E0.07282
G1 X66.459 Y31.008 E0.03194
G1 X66.459 Y22.012 E0.07282
G1 X69.454 Y22.012 E0.02424
G1 X69.454 Y31.008 E0.07282
G1 X73.466 Y31.008 E0.03248
G1 X73.466 Y22.012 E0.07282
G1 X76.483 Y22.012 E0.02442
G1 X76.483 Y31.222 E0.07456
G1 X74.907 Y32.017 E0.01429
G1 X60.475 Y32.017 E0.11682
G1 X60.475 Y22.060 E0.08060
G1 F1800.000 E-0.01000 // Replace that whole line by M42 P4 S0
G1 X60.154 Y21.690 F7800.000
G1 E0.01000 F1800.000
M42 P4 S255 // This line added after the script see E0.01000 term
G1 X62.835 Y21.690 E0.02170 F960.000

I'm not familiar with that kind of code since I only know (roughly) MATLAB type code language.

Is this possible? Does anyone would be able to write that short script for me?

Thanks all
Re: Post-processing script
April 09, 2014 05:21PM
If you are om a Linux or other box with some *nix tools, the following will do it quick an dirty:

cat some.gcode | perl -pi -e "s/^G1.*E-.*$/M42 P4 S0/" | perl -pi -e "s/^(G1 E0.01000.*)$/\1\nM42 P4 S255/" > someother.gcode
Re: Post-processing script
April 09, 2014 07:31PM
I am using Repetier-host with Slic3r on a Windows 7 PC. I noticed in the Slic3r settings that I can add the path for a post-processing script that would automatically modify my gcode file. That is what I am looking for.

Thanks
Re: Post-processing script
April 10, 2014 01:34AM
If you install Perl a script could look like this:

open(GCODE, $ARGV[0]) or die("Could not open  file.");

foreach $line (< GCODE > ) {
        chomp($line);
        $line =~ s/^G1.*E-.*$/M42 P4 S0/;
        $line =~ s/^(G1 E0.01000.*)$/\1\nM42 P4 S255/;
        print "$line\n";
}
close(GCODE);

Remove the extra spaces in the 'foreach' line.

I'm not sure you can do it with native Windows tools, as regular expressions isn't all that common in the Microsoft world, back in the days with NT, "Jscript" had an engine for regular expressions, but it wasn't really a plessant feeling to work with. winking smiley

Edited 1 time(s). Last edit at 04/10/2014 01:34AM by Ralf.
Re: Post-processing script
April 10, 2014 08:09AM
I will give this a try. Thank you very much!
Re: Post-processing script
April 15, 2014 12:56PM
I installed Perl and associated *.pl files with the software. Now, after slicing the model, Slic3r runs the post-processing script automatically with Perl. The problem is that the scripts posted here do not seem to do anything. I am not familiar with that code so I would love if someone could do it for me (if it's not too hard).

Here is an example of a script ran by Slic3r via Perl :

#!/usr/bin/perl -i

use strict;
use warnings;

my $z = 0;

# read stdin and any/all files passed as parameters one line at a time
while (< > ) {
# if we find a Z word, save it
$z = $1 if /Z\s*(\d+(\.\d+)?)/;

# if we don't have Z, but we do have X and Y
if (!/Z/ && /X/ && /Y/ && $z > 0) {
# chop off the end of the line (incl. comments), saving chopped section in $1
s/\s*([\r\n\;\(].*)/" Z$z $1"/es;
# print start of line, insert our Z value then re-add the chopped end of line
# print "$_ Z$z $1";
}
#else {
# nothing interesting, print line as-is
print or die $!;
#}
}


References for post-processing scripts :
[manual.slic3r.org]
[github.com]
[github.com]

I also managed to find the right glass coating that won't stick to the printed part and will let the UV pass thru the glass.

Thanks

Edited 3 time(s). Last edit at 04/15/2014 12:57PM by PierreYves.Pepin.
Re: Post-processing script
April 24, 2014 09:22AM
Hey guys, here is an update. I am now able to run the scripts via Perl (cmd box) with these commands (see image below). Once it runs the script, my gcode file is now modified with the added command lines.


The problem is that I still can't post-process my gcodes automatically with Slic3r. The path to the post-processing script is good and the script itself is also good (working via cmd box). Repetier says that it runs the script but no changes are made to my gcode....



Here is the script :

#!/usr/bin/perl -i.before_postproc
#
# Author  : Guy Poizat
# Version : 1.2
# Copyright : none.
#
# Change from previous version : added handling of slic3r's retraction speed setting,
#  so that this script is not disrupted by a setting change.

use strict;
use warnings;

# what will replace a retraction line with : gcode to cut the laser power off.
my $powerOffLine = "M42 P4 S0\n";

# what will replace an "unretraction" line with : gcode to switch the laser power on.
my $powerOnLine = "M42 P4 S255\n";

# Extract the speed setting from slic3r's environment variables (or use the default 30mm/s).
#  Unit is millimeters per minute in gcode, millimeters per second in slic3r configuration.
my $defaultRetractSpeed = 1800;
my $envRetractSpeed = $ENV{"SLIC3R_RETRACT_SPEED"};
my $retractSpeed = defined( $envRetractSpeed ) ? $envRetractSpeed * 60 : $defaultRetractSpeed;

# pattern of a retraction line - would make the filament back-off before a non printing move
#  on a FDM 3d printer, to avoid ooze.
my $retractLine = "G1 F$retractSpeed.* E";

# pattern of an unretraction line - would make the filament forward back to its position before starting extruding again.
my $unretractLine = "G1 E.* F$retractSpeed";

# read stdin and any/all files passed as parameters one line at a time
while (< > ) {
	if (/$retractLine/) {
		# if we found a retraction line, replace it with laser power off
		print "$powerOffLine";
	}
	else {
		# nothing to change, print line as-is
		print or die $!;
	}
	
	if (/$unretractLine/) {
		# if we have an un-retraction line, append laser power on right after it
		print "$powerOnLine";
	}
}


Can someone figure out what my problem is?

Edited 3 time(s). Last edit at 04/24/2014 09:24AM by PierreYves.Pepin.
Re: Post-processing script
April 24, 2014 12:54PM
I am not a windows or slic3r user but I think the problem may be that you need to call perl before the script (at least that is the way you use scripts in Linux).

perl C:\DATA\Repra..............

Edited 1 time(s). Last edit at 04/24/2014 12:55PM by Sublime.


FFF Settings Calculator Gcode post processors Geometric Object Deposition Tool Blog
Tantillus.org Mini Printable Lathe How NOT to install a Pololu driver
Re: Post-processing script
April 24, 2014 02:53PM
Where should I add this? The person who wrote the script (DeuxVis on the forum), has no problem executing automatically it with his Repetier/Slic3r.
Re: Post-processing script
April 24, 2014 03:06PM
Quote
PierreYves.Pepin
Where should I add this? The person who wrote the script (DeuxVis on the forum), has no problem executing automatically it with his Repetier/Slic3r.

You would just add "perl" in front of the command you typed into slic3r. This would tell the OS to execute the script using perl.

But again I am not a Windows or Slic3r user so it may not be the answer but worth a try.


FFF Settings Calculator Gcode post processors Geometric Object Deposition Tool Blog
Tantillus.org Mini Printable Lathe How NOT to install a Pololu driver
Re: Post-processing script
April 24, 2014 03:08PM
The script itself (*.pl) is already associated with Perl so Slic3r execute it using Perl. It's kinda weird because DeuxVis is able to post-process the gcode using Repetier. Even if I use his configs, I still do not have nothing.
Re: Post-processing script
April 24, 2014 03:09PM
I do notice that at the top of the script he has
#!/usr/bin/perl -i.before_postproc
Which is a path to perl on Linux so maybe the fact he is a linux user could be affecting this.


FFF Settings Calculator Gcode post processors Geometric Object Deposition Tool Blog
Tantillus.org Mini Printable Lathe How NOT to install a Pololu driver
Re: Post-processing script
April 24, 2014 03:26PM
Hi.

For me work the following way with a AutoIt script:

1. Make Windows familiar for the Script extension - (here bundle .au3 with the host programm E:\tools\Autoit_3_neu\AutoIt3_x64.exe" "%1" )
((.au3 is the extension for the script text as ascii code))

2. Insert the complete path and file name to the sli3r "Output options" (Example - e:\tools\Autoit_3_neu\joro\3D-Drucker\Slic3r-Post_Process.au3)

3.Handle in the script the default path and name for the "composition.gcode" file (Repetier settings)
(Read in, and after processing write to the same file name.)

So the manipulated Gcode is direkt show in the repetier window.

JoRo
Re: Post-processing script
January 15, 2015 08:07PM
Very interesting, I've been trying to get this to work on my mac. Everything is in working order, the only thing the script doesn't do, is replace the retract line with the new code I want to put there (M104 S0 and M104 S100 in my case).

Anyone who got this to work on mac?


http://www.marinusdebeer.nl/
Re: Post-processing script
January 18, 2015 10:24AM
Hey guys, just checking back to say that I fixed the script.

Problem is this line:
while (< > ) {

It should be:
while (<> ) {

or:
while ( ) {

However, my laser sometimes turns off on moments that it doesn't need to turn off, and then it skips parts so not sure how to improve this even more.

Edited 1 time(s). Last edit at 01/18/2015 10:24AM by Ohmarinus.


http://www.marinusdebeer.nl/
Sorry, only registered users may post in this forum.

Click here to login