From 107f48d8942cf5c65c739a0ff825b5a9d63bee7d Mon Sep 17 00:00:00 2001 From: Alessandro Ranellucci Date: Sun, 10 Mar 2013 17:28:03 +0100 Subject: [PATCH] Reduce toolchanges by giving priority to last extruder on layer change. #940 --- lib/Slic3r/Print.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Slic3r/Print.pm b/lib/Slic3r/Print.pm index afd352431..521988c74 100644 --- a/lib/Slic3r/Print.pm +++ b/lib/Slic3r/Print.pm @@ -846,7 +846,15 @@ sub write_gcode { # set actual Z - this will force a retraction $gcode .= $gcodegen->move_z($layer->print_z); - foreach my $region_id (0 .. ($self->regions_count-1)) { + # tweak region ordering to save toolchanges + my @region_ids = 0 .. ($self->regions_count-1); + if ($gcodegen->multiple_extruders) { + my $last_extruder = $gcodegen->extruder; + my $best_region_id = first { $self->regions->[$_]->extruders->{perimeter} eq $last_extruder } @region_ids; + @region_ids = ($best_region_id, grep $_ != $best_region_id, @region_ids); + } + + foreach my $region_id (@region_ids) { my $layerm = $layer->regions->[$region_id]; my $region = $self->regions->[$region_id];