diff --git a/src/libslic3r/GCode.cpp b/src/libslic3r/GCode.cpp index 6db84d030..6d89ded72 100644 --- a/src/libslic3r/GCode.cpp +++ b/src/libslic3r/GCode.cpp @@ -1605,9 +1605,24 @@ void GCode::_do_export(Print& print, FILE* file, ThumbnailsGeneratorCallback thu print.throw_if_canceled(); } -std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override) +std::string GCode::placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, DynamicConfig *config_override) { + DynamicConfig default_config; + if (config_override == nullptr) + config_override = &default_config; try { + //add some config conversion for colors + auto func_add_colour = [config_override](std::string key, std::string colour) { + if (colour.length() == 7) { + config_override->set_key_value(key, new ConfigOptionInt((int)strtol(colour.substr(1, 6).c_str(), NULL, 16))); + } + }; + if (current_extruder_id >= 0 && current_extruder_id < config().filament_colour.size()) { + func_add_colour("filament_colour_int", config().filament_colour.values[current_extruder_id]); + func_add_colour("extruder_colour_int", config().extruder_colour.values[current_extruder_id]); + } + func_add_colour("thumbnails_color_int", config().thumbnails_color); + std::string gcode = m_placeholder_parser.process(templ, current_extruder_id, config_override, &m_placeholder_parser_context); if (!gcode.empty() && m_config.gcode_comments) { gcode = "; custom gcode: " + name + "\n" + gcode; diff --git a/src/libslic3r/GCode.hpp b/src/libslic3r/GCode.hpp index f906d56d5..b9724a3a8 100644 --- a/src/libslic3r/GCode.hpp +++ b/src/libslic3r/GCode.hpp @@ -170,7 +170,7 @@ public: const PlaceholderParser& placeholder_parser() const { return m_placeholder_parser; } // Process a template through the placeholder parser, collect error messages to be reported // inside the generated string and after the G-code export finishes. - std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, const DynamicConfig *config_override = nullptr); + std::string placeholder_parser_process(const std::string &name, const std::string &templ, unsigned int current_extruder_id, DynamicConfig *config_override = nullptr); bool enable_cooling_markers() const { return m_enable_cooling_markers; } std::string extrusion_role_to_string_for_parser(const ExtrusionRole &);