Last active
December 6, 2018 09:42
-
-
Save blind-coder/42948912a76bb64c393a1db74bbdda6f to your computer and use it in GitHub Desktop.
Simple GCode Absolute Extrusion to Relative Extrusion converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# Permission is hereby granted, free of charge, to any person obtaining a copy of | |
# this software and associated documentation files (the "Software"), to deal in | |
# the Software without restriction, including without limitation the rights to | |
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | |
# of the Software, and to permit persons to whom the Software is furnished to do | |
# so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
use strict; | |
use bignum; | |
my $absPos = 0; | |
my $mode = "absolute"; | |
while (<STDIN>){ | |
chomp; chomp; | |
for ($_){ | |
if (/^M83$/){ | |
$mode = "relative"; | |
print "M83\n"; | |
} elsif (/^M82$/){ | |
$mode = "absolute"; | |
print "M83\n"; # keep relative mode in output | |
} elsif (/^G92(.*?)(E([0-9\.-]+))(.*$)/){ | |
my ($fill1, $E, $extrusion, $fill2) = ($1, $2, $3); | |
$fill1 = "" unless defined($fill1); | |
$fill2 = "" unless defined($fill2); | |
$absPos = $extrusion; | |
print "$_\n"; | |
} elsif (/^G([01235])(.*?)(E([0-9\.-]+))(.*$)/){ | |
my $relExtrusion = 0; | |
my ($code, $fill1, $E, $extrusion, $fill2) = ($1, $2, $3, $4); | |
$fill1 = "" unless defined($fill1); | |
$fill2 = "" unless defined($fill2); | |
if ($mode eq "relative"){ | |
$absPos = $absPos + $extrusion; | |
$relExtrusion = $extrusion; | |
} else { | |
$relExtrusion = $extrusion - $absPos; | |
$absPos = $extrusion; | |
} | |
printf "G$code $fill1 E%.5f $fill2\n", $relExtrusion; | |
} else { | |
print "$_\n"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple GCode Absolute to Relative Extrusion converter
I needed a simple solution to stitch differently sliced .gcode files together. Unfortunately, my slicer (Cura-2.7.0) does not support relative extrusion, so I wrote this little script to convert absolute extrusion to relative extrusion.
USE AT YOUR OWN RISK!