Skip to content

Commit

Permalink
New --before-layer-change option and new layer_z placeholder. #2602
Browse files Browse the repository at this point in the history
  • Loading branch information
alranel committed Jan 30, 2015
1 parent 2d3fdf9 commit 059b00a
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -219,7 +219,8 @@ The author of the Silk icon set is Mark James.
--end-gcode Load final G-code from the supplied file. This will overwrite
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).
--before-layer-gcode Load before-layer-change G-code from the supplied file (default: nothing).
--layer-gcode Load after-layer-change G-code from the supplied file (default: nothing).
--toolchange-gcode Load tool-change G-code from the supplied file (default: nothing).
--seam-position Position of loop starting points (random/nearest/aligned, default: aligned).
--external-perimeters-first Reverse perimeter order. (default: no)
Expand Down
13 changes: 11 additions & 2 deletions lib/Slic3r/GUI/Tab.pm
Expand Up @@ -945,7 +945,7 @@ sub build {
octoprint_host octoprint_apikey
use_firmware_retraction pressure_advance vibration_limit
use_volumetric_e
start_gcode end_gcode layer_gcode toolchange_gcode
start_gcode end_gcode before_layer_gcode layer_gcode toolchange_gcode
nozzle_diameter extruder_offset
retract_length retract_lift retract_speed retract_restart_extra retract_before_travel retract_layer_change wipe
retract_length_toolchange retract_restart_extra_toolchange
Expand Down Expand Up @@ -1110,7 +1110,16 @@ sub build {
$optgroup->append_single_option_line($option);
}
{
my $optgroup = $page->new_optgroup('Layer change G-code',
my $optgroup = $page->new_optgroup('Before layer change G-code',
label_width => 0,
);
my $option = $optgroup->get_option('before_layer_gcode');
$option->full_width(1);
$option->height(150);
$optgroup->append_single_option_line($option);
}
{
my $optgroup = $page->new_optgroup('After layer change G-code',
label_width => 0,
);
my $option = $optgroup->get_option('layer_gcode');
Expand Down
5 changes: 5 additions & 0 deletions lib/Slic3r/Print/GCode.pm
Expand Up @@ -318,9 +318,14 @@ sub process_layer {
}

# set new layer - this will change Z and force a retraction if retract_layer_change is enabled
$gcode .= $self->_gcodegen->placeholder_parser->process($self->print->config->before_layer_gcode, {
layer_num => $layer->id,
layer_z => $layer->print_z,
}) . "\n" if $self->print->config->before_layer_gcode;
$gcode .= $self->_gcodegen->change_layer($layer);
$gcode .= $self->_gcodegen->placeholder_parser->process($self->print->config->layer_gcode, {
layer_num => $layer->id,
layer_z => $layer->print_z,
}) . "\n" if $self->print->config->layer_gcode;

# extrude skirt
Expand Down
1 change: 1 addition & 0 deletions slic3r.pl
Expand Up @@ -371,6 +371,7 @@ sub usage {
--end-gcode Load final G-code from the supplied file. This will overwrite
the default commands (turn off temperature [M104 S0],
home X axis [G28 X], disable motors [M84]).
--before-layer-gcode Load before-layer-change G-code from the supplied file (default: nothing).
--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).
--seam-position Position of loop starting points (random/nearest/aligned, default: $config->{seam_position}).
Expand Down
14 changes: 11 additions & 3 deletions xs/src/libslic3r/PrintConfig.cpp
Expand Up @@ -22,6 +22,14 @@ PrintConfigDef::build_def() {
Options["bed_temperature"].min = 0;
Options["bed_temperature"].max = 300;

Options["before_layer_gcode"].type = coString;
Options["before_layer_gcode"].label = "Before layer change G-code";
Options["before_layer_gcode"].tooltip = "This custom code is inserted at every layer change, right before the Z move. Note that you can use placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z].";
Options["before_layer_gcode"].cli = "before-layer-gcode=s";
Options["before_layer_gcode"].multiline = true;
Options["before_layer_gcode"].full_width = true;
Options["before_layer_gcode"].height = 50;

Options["bottom_solid_layers"].type = coInt;
Options["bottom_solid_layers"].label = "Bottom";
Options["bottom_solid_layers"].category = "Layers and Perimeters";
Expand Down Expand Up @@ -438,9 +446,9 @@ PrintConfigDef::build_def() {
Options["interface_shells"].category = "Layers and Perimeters";

Options["layer_gcode"].type = coString;
Options["layer_gcode"].label = "Layer change G-code";
Options["layer_gcode"].tooltip = "This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings.";
Options["layer_gcode"].cli = "layer-gcode=s";
Options["layer_gcode"].label = "After layer change G-code";
Options["layer_gcode"].tooltip = "This custom code is inserted at every layer change, right after the Z move and before the extruder moves to the first layer point. Note that you can use placeholder variables for all Slic3r settings as well as [layer_num] and [layer_z].";
Options["layer_gcode"].cli = "after-layer-gcode|layer-gcode=s";
Options["layer_gcode"].multiline = true;
Options["layer_gcode"].full_width = true;
Options["layer_gcode"].height = 50;
Expand Down
3 changes: 3 additions & 0 deletions xs/src/libslic3r/PrintConfig.hpp
Expand Up @@ -324,6 +324,7 @@ class PrintRegionConfig : public virtual StaticPrintConfig
class GCodeConfig : public virtual StaticPrintConfig
{
public:
ConfigOptionString before_layer_gcode;
ConfigOptionString end_gcode;
ConfigOptionString extrusion_axis;
ConfigOptionFloats extrusion_multiplier;
Expand All @@ -346,6 +347,7 @@ class GCodeConfig : public virtual StaticPrintConfig
ConfigOptionBool use_volumetric_e;

GCodeConfig() : StaticPrintConfig() {
this->before_layer_gcode.value = "";
this->end_gcode.value = "M104 S0 ; turn off temperature\nG28 X0 ; home X axis\nM84 ; disable motors\n";
this->extrusion_axis.value = "E";
this->extrusion_multiplier.values.resize(1);
Expand Down Expand Up @@ -377,6 +379,7 @@ class GCodeConfig : public virtual StaticPrintConfig
};

ConfigOption* option(const t_config_option_key opt_key, bool create = false) {
if (opt_key == "before_layer_gcode") return &this->before_layer_gcode;
if (opt_key == "end_gcode") return &this->end_gcode;
if (opt_key == "extrusion_axis") return &this->extrusion_axis;
if (opt_key == "extrusion_multiplier") return &this->extrusion_multiplier;
Expand Down

0 comments on commit 059b00a

Please sign in to comment.