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

[FEATURE] Add bed/plate number to output filename #7

Merged
merged 1 commit into from
Jan 8, 2025
Merged
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
3 changes: 3 additions & 0 deletions src/libslic3r/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,9 @@ void GCodeGenerator::_do_export(Print& print, GCodeOutputStream &file, Thumbnail
this->placeholder_parser().set("has_wipe_tower", has_wipe_tower);
this->placeholder_parser().set("has_single_extruder_multi_material_priming", has_wipe_tower && print.config().single_extruder_multi_material_priming);
this->placeholder_parser().set("total_toolchanges", tool_ordering.toolchanges_count());

this->placeholder_parser().set("bed_number", new ConfigOptionString(print.get_bed_number_formatted()));

{
BoundingBoxf bbox(print.config().bed_shape.values);
assert(bbox.defined);
Expand Down
10 changes: 10 additions & 0 deletions src/libslic3r/Print.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
#include "libslic3r/GCode/ConflictChecker.hpp"
#include "Utils.hpp"
#include "BuildVolume.hpp"
#include "MultipleBeds.hpp"
#include "format.hpp"

#include <float.h>
Expand Down Expand Up @@ -1666,6 +1667,7 @@ std::string Print::output_filename(const std::string &filename_base) const
DynamicConfig config = this->finished() ? this->print_statistics().config() : this->print_statistics().placeholders();
config.set_key_value("num_extruders", new ConfigOptionInt((int)m_config.nozzle_diameter.size()));
config.set_key_value("default_output_extension", new ConfigOptionString(".gcode"));
config.set_key_value("bed_number", new ConfigOptionString(get_bed_number_formatted()));

// Handle output_filename_format. There is a hack related to binary G-codes: gcode / bgcode substitution.
std::string output_filename_format = m_config.output_filename_format.value;
Expand All @@ -1677,6 +1679,14 @@ std::string Print::output_filename(const std::string &filename_base) const
return this->PrintBase::output_filename(output_filename_format, ".gcode", filename_base, &config);
}

std::string Print::get_bed_number_formatted() const
{
std::string bed_number = std::to_string(s_multiple_beds.get_active_bed() + 1);
static const size_t n_zero = 2;

return std::string(n_zero - std::min(n_zero, bed_number.length()), '0') + bed_number;
}

// Returns if all used filaments have same shrinkage compensations.
bool Print::has_same_shrinkage_compensations() const {
const std::vector<unsigned int> extruders = this->extruders();
Expand Down
2 changes: 2 additions & 0 deletions src/libslic3r/Print.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,8 @@ class Print : public PrintBaseWithState<PrintStep, psCount>

std::string output_filename(const std::string &filename_base = std::string()) const override;

std::string get_bed_number_formatted() const;

size_t num_print_regions() const throw() { return m_print_regions.size(); }
const PrintRegion& get_print_region(size_t idx) const { return *m_print_regions[idx]; }
const ToolOrdering& get_tool_ordering() const { return m_wipe_tower_data.tool_ordering; }
Expand Down
Loading