Allow to use config options in start/end G-code
This commit is contained in:
parent
f2032686da
commit
d0807aa807
@ -619,4 +619,23 @@ sub validate {
|
|||||||
$Slic3r::solid_infill_speed ||= $Slic3r::infill_speed;
|
$Slic3r::solid_infill_speed ||= $Slic3r::infill_speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub replace_options {
|
||||||
|
my $class = shift;
|
||||||
|
my ($string, $more_variables) = @_;
|
||||||
|
|
||||||
|
if ($more_variables) {
|
||||||
|
my $variables = join '|', keys %$more_variables;
|
||||||
|
$string =~ s/\[($variables)\]/$more_variables->{$1}/eg;
|
||||||
|
}
|
||||||
|
|
||||||
|
# build a regexp to match the available options
|
||||||
|
my $options = join '|',
|
||||||
|
grep !$Slic3r::Config::Options->{$_}{multiline},
|
||||||
|
keys %$Slic3r::Config::Options;
|
||||||
|
|
||||||
|
# use that regexp to search and replace option names with option values
|
||||||
|
$string =~ s/\[($options)\]/Slic3r::Config->serialize($1)/eg;
|
||||||
|
return $string;
|
||||||
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
@ -592,7 +592,7 @@ sub export_gcode {
|
|||||||
printf $fh "M104 %s%d ; set temperature\n",
|
printf $fh "M104 %s%d ; set temperature\n",
|
||||||
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::first_layer_temperature
|
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::first_layer_temperature
|
||||||
if $Slic3r::first_layer_temperature;
|
if $Slic3r::first_layer_temperature;
|
||||||
print $fh "$Slic3r::start_gcode\n";
|
printf $fh "%s\n", Slic3r::Config->replace_options($Slic3r::start_gcode);
|
||||||
printf $fh "M109 %s%d ; wait for temperature to be reached\n",
|
printf $fh "M109 %s%d ; wait for temperature to be reached\n",
|
||||||
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::first_layer_temperature
|
($Slic3r::gcode_flavor eq 'mach3' ? 'P' : 'S'), $Slic3r::first_layer_temperature
|
||||||
if $Slic3r::first_layer_temperature && $Slic3r::gcode_flavor ne 'makerbot';
|
if $Slic3r::first_layer_temperature && $Slic3r::gcode_flavor ne 'makerbot';
|
||||||
@ -720,7 +720,7 @@ sub export_gcode {
|
|||||||
print $fh $extruder->retract;
|
print $fh $extruder->retract;
|
||||||
print $fh $extruder->set_fan(0);
|
print $fh $extruder->set_fan(0);
|
||||||
print $fh "M501 ; reset acceleration\n" if $Slic3r::acceleration;
|
print $fh "M501 ; reset acceleration\n" if $Slic3r::acceleration;
|
||||||
print $fh "$Slic3r::end_gcode\n";
|
printf $fh "%s\n", Slic3r::Config->replace_options($Slic3r::end_gcode);
|
||||||
|
|
||||||
printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
|
printf $fh "; filament used = %.1fmm (%.1fcm3)\n",
|
||||||
$self->total_extrusion_length, $self->total_extrusion_volume;
|
$self->total_extrusion_length, $self->total_extrusion_volume;
|
||||||
|
@ -163,19 +163,13 @@ sub expanded_output_filepath {
|
|||||||
# file directory and append the specified filename format
|
# file directory and append the specified filename format
|
||||||
$path ||= (fileparse($self->input_file))[1] . $Slic3r::output_filename_format;
|
$path ||= (fileparse($self->input_file))[1] . $Slic3r::output_filename_format;
|
||||||
|
|
||||||
my $input_basename = basename($self->input_file);
|
my $input_filename = my $input_filename_base = basename($self->input_file);
|
||||||
$path =~ s/\[input_filename\]/$input_basename/g;
|
$input_filename_base =~ s/\.(?:stl|amf(?:\.xml)?)$//i;
|
||||||
$input_basename =~ s/\.(?:stl|amf(?:\.xml)?)$//i;
|
|
||||||
$path =~ s/\[input_filename_base\]/$input_basename/g;
|
|
||||||
|
|
||||||
# build a regexp to match the available options
|
return Slic3r::Config->replace_options($path, {
|
||||||
my $options = join '|',
|
input_filename => $input_filename,
|
||||||
grep !$Slic3r::Config::Options->{$_}{multiline},
|
input_filename_base => $input_filename_base,
|
||||||
keys %$Slic3r::Config::Options;
|
});
|
||||||
|
|
||||||
# use that regexp to search and replace option names with option values
|
|
||||||
$path =~ s/\[($options)\]/Slic3r::Config->serialize($1)/eg;
|
|
||||||
return $path;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
1;
|
1;
|
||||||
|
Loading…
Reference in New Issue
Block a user