Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New macros variable - layer_used_filament #4380

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3094,11 +3094,30 @@ LayerResult GCode::process_layer(
// Set new layer - this will change Z and force a retraction if retract_layer_change is enabled.
coordf_t previous_print_z = m_layer != nullptr ? m_layer->print_z : 0;
if (! print.config().before_layer_gcode.value.empty()) {
std::vector<double> layer_used_filament(m_writer.extruders().size());

PrintStatistics & stats = status_monitor.stats();
if (! m_writer.extruders().empty()) {
for (const Extruder &extruder : m_writer.extruders()) {
double used_filament = extruder.used_filament() + (print.has_wipe_tower() ? print.wipe_tower_data().used_filament[extruder.id()] : 0.f);

if (extruder.id() >= layer_used_filament.size()) {
layer_used_filament.resize(extruder.id() + 1);
}

double layer_filament = used_filament - stats.total_used_filament_before_current_layer[extruder.id()];

layer_used_filament[extruder.id()] = ((layer_filament > 0.f) ? layer_filament : 0.f);
stats.total_used_filament_before_current_layer[extruder.id()] = used_filament;
}
}

DynamicConfig config;
config.set_key_value("previous_layer_z", new ConfigOptionFloat(previous_print_z));
config.set_key_value("layer_num", new ConfigOptionInt(m_layer_index + 1));
config.set_key_value("layer_z", new ConfigOptionFloat(print_z));
config.set_key_value("max_layer_z", new ConfigOptionFloat(m_max_layer_z));
config.set_key_value("layer_used_filament", new ConfigOptionFloats(layer_used_filament));
gcode += this->placeholder_parser_process("before_layer_gcode",
print.config().before_layer_gcode.value, m_writer.tool()->id(), &config)
+ "\n";
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,7 @@ struct PrintStatistics
std::string initial_filament_type;
std::string printing_filament_types;
std::map<size_t, double> filament_stats; // extruder id -> volume in mm3
std::map<size_t, double> total_used_filament_before_current_layer; // extruder id -> mm (length)

std::atomic_bool is_computing_gcode;

Expand All @@ -520,6 +521,7 @@ struct PrintStatistics
initial_filament_type.clear();
printing_filament_types.clear();
filament_stats.clear();
total_used_filament_before_current_layer.clear();
printing_extruders.clear();
is_computing_gcode = false;
}
Expand Down