From a790497a85c087226c745ad040778c16cd3754ac Mon Sep 17 00:00:00 2001 From: dshmyglev Date: Thu, 18 Jul 2024 11:53:37 +0300 Subject: [PATCH] New macros variable - layer_used_filament --- src/libslic3r/GCode.cpp | 19 +++++++++++++++++++ src/libslic3r/Print.hpp | 2 ++ 2 files changed, 21 insertions(+) diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 840fcd16c38..07504c32c44 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -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 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"; diff --git a/src/libslic3r/Print.hpp b/src/libslic3r/Print.hpp index f72bfcfe2e7..2656eaa1f0d 100644 --- a/src/libslic3r/Print.hpp +++ b/src/libslic3r/Print.hpp @@ -498,6 +498,7 @@ struct PrintStatistics std::string initial_filament_type; std::string printing_filament_types; std::map filament_stats; // extruder id -> volume in mm3 + std::map total_used_filament_before_current_layer; // extruder id -> mm (length) std::atomic_bool is_computing_gcode; @@ -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; }