diff --git a/README.markdown b/README.markdown index b355f935b..43bf64017 100644 --- a/README.markdown +++ b/README.markdown @@ -176,6 +176,7 @@ The author of the Silk icon set is Mark James. the default commands (turn off temperature [M104 S0], home X axis [G28 X], disable motors [M84]). --layer-gcode Load layer-change G-code from the supplied file (default: nothing). + --toolchange-gcode Load tool-change G-code from the supplied file (default: nothing). --extra-perimeters Add more perimeters when needed (default: yes) --randomize-start Randomize starting point across layers (default: yes) --only-retract-when-crossing-perimeters diff --git a/lib/Slic3r/Config.pm b/lib/Slic3r/Config.pm index 44d748955..c9594cac3 100644 --- a/lib/Slic3r/Config.pm +++ b/lib/Slic3r/Config.pm @@ -607,6 +607,18 @@ END deserialize => sub { join "\n", split /\\n/, $_[0] }, default => '', }, + 'toolchange_gcode' => { + label => 'Tool change G-code', + tooltip => 'This custom code is inserted at every extruder change. Note that you can use placeholder variables for all Slic3r settings as well as [previous_extruder] and [next_extruder].', + cli => 'toolchange-gcode=s', + type => 's', + multiline => 1, + full_width => 1, + height => 50, + serialize => sub { join '\n', split /\R+/, $_[0] }, + deserialize => sub { join "\n", split /\\n/, $_[0] }, + default => '', + }, 'post_process' => { label => 'Post-processing scripts', tooltip => 'If you want to process the output G-code through custom scripts, just list their absolute paths here. Separate multiple scripts with a semicolon. Scripts will be passed the absolute path to the G-code file as the first argument, and they can access the Slic3r config settings by reading environment variables.', @@ -925,7 +937,7 @@ sub new_from_cli { delete $args{$_} for grep !defined $args{$_}, keys %args; - for (qw(start end layer)) { + for (qw(start end layer toolchange)) { my $opt_key = "${_}_gcode"; if ($args{$opt_key}) { die "Invalid value for --${_}-gcode: file does not exist\n" diff --git a/lib/Slic3r/GCode.pm b/lib/Slic3r/GCode.pm index d71be3040..2bf141556 100644 --- a/lib/Slic3r/GCode.pm +++ b/lib/Slic3r/GCode.pm @@ -442,6 +442,14 @@ sub set_extruder { my $gcode = ""; $gcode .= $self->retract(toolchange => 1) if defined $self->extruder; + # append custom toolchange G-code + if (defined $self->extruder && $Slic3r::Config->toolchange_gcode) { + $gcode .= sprintf "%s\n", $Slic3r::Config->replace_options($Slic3r::Config->toolchange_gcode, { + previous_extruder => $self->extruder->id, + next_extruder => $extruder->id, + }); + } + # set the new extruder $self->extruder($extruder); $gcode .= sprintf "T%d%s\n", $extruder->id, ($Slic3r::Config->gcode_comments ? ' ; change extruder' : ''); diff --git a/lib/Slic3r/GUI/Tab.pm b/lib/Slic3r/GUI/Tab.pm index 646b62e3e..d4479d6bd 100644 --- a/lib/Slic3r/GUI/Tab.pm +++ b/lib/Slic3r/GUI/Tab.pm @@ -656,6 +656,11 @@ sub build { no_labels => 1, options => [qw(layer_gcode)], }, + { + title => 'Tool change G-code', + no_labels => 1, + options => [qw(toolchange_gcode)], + }, ]); $self->{extruder_pages} = []; diff --git a/slic3r.pl b/slic3r.pl index b4325abf1..51a58271d 100755 --- a/slic3r.pl +++ b/slic3r.pl @@ -224,6 +224,7 @@ $j the default commands (turn off temperature [M104 S0], home X axis [G28 X], disable motors [M84]). --layer-gcode Load layer-change G-code from the supplied file (default: nothing). + --toolchange-gcode Load tool-change G-code from the supplied file (default: nothing). --extra-perimeters Add more perimeters when needed (default: yes) --randomize-start Randomize starting point across layers (default: yes) --only-retract-when-crossing-perimeters