From 3c0057380582700ddf975079b682932ae2db6b03 Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Fri, 6 Jul 2012 19:57:58 +0200 Subject: [PATCH] Reset E and compensate retraction after changing extruder --- lib/Slic3r/GCode.pm | 18 +++++++++++++----- lib/Slic3r/Print.pm | 3 +-- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index f3afcd985..58d0eed51 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -247,10 +247,7 @@ sub retract { # reset extrusion distance during retracts # this makes sure we leave sufficient precision in the firmware - if (!$Slic3r::use_relative_e_distances && $Slic3r::gcode_flavor !~ /^(?:mach3|makerbot)$/) { - $gcode .= "G92 " . $Slic3r::extrusion_axis . "0\n" if $Slic3r::extrusion_axis; - $self->extrusion_distance(0); - } + $gcode .= $self->reset_e if $Slic3r::gcode_flavor !~ /^(?:mach3|makerbot)$/; return $gcode; } @@ -272,6 +269,14 @@ sub unretract { return $gcode; } +sub reset_e { + my $self = shift; + + $self->extrusion_distance(0); + return "G92 %s0%s\n", $Slic3r::extrusion_axis, ($Slic3r::gcode_comments ? ' ; reset extrusion distance' : '') + if $Slic3r::extrusion_axis && !$Slic3r::use_relative_e_distances; +} + sub set_acceleration { my $self = shift; my ($acceleration) = @_; @@ -382,7 +387,10 @@ sub set_tool { return "" if $self->extruder_idx == $tool; $self->extruder_idx($tool); - return $self->retract . sprintf "T%d%s\n", $tool, ($Slic3r::gcode_comments ? ' ; change tool' : ''); + return $self->retract + . sprintf "T%d%s\n", $tool, ($Slic3r::gcode_comments ? ' ; change tool' : '') + . $self->reset_e + . $self->unretract; } sub set_fan { diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index a1904cd10..6e9cc558a 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -530,8 +530,7 @@ sub write_gcode { print $fh "G90 ; use absolute coordinates\n"; print $fh "G21 ; set units to millimeters\n"; if ($Slic3r::gcode_flavor =~ /^(?:reprap|teacup)$/) { - printf $fh "G92 %s0 ; reset extrusion distance\n", $Slic3r::extrusion_axis - if $Slic3r::extrusion_axis && !$Slic3r::use_relative_e_distances; + printf $fh $gcodegen->reset_e; if ($Slic3r::gcode_flavor =~ /^(?:reprap|makerbot)$/) { if ($Slic3r::use_relative_e_distances) { print $fh "M83 ; use relative distances for extrusion\n";