diff --git a/src/libslic3r/Preset.cpp b/src/libslic3r/Preset.cpp index 61463dd81f9..60ead0f814f 100644 --- a/src/libslic3r/Preset.cpp +++ b/src/libslic3r/Preset.cpp @@ -638,6 +638,23 @@ void Preset::save(DynamicPrintConfig* parent_config) //BBS: add project embedded preset logic if (this->is_project_embedded) return; + + // Generate a unique filament_id for user filament presets that don't have one yet. + // Inherited presets (e.g. "My PLA" inheriting "Generic PLA @System") previously had + // no filament_id which caused AMS sync to fall back to the parent's Generic ID. + if (this->is_user() && this->filament_id.empty() && !this->name.empty() && + this->type() == Preset::TYPE_FILAMENT) { + boost::uuids::detail::md5 hash; + boost::uuids::detail::md5::digest_type digest; + hash.process_bytes(this->name.data(), this->name.size()); + hash.get_digest(digest); + const auto char_digest = reinterpret_cast(&digest); + std::string result; + boost::algorithm::hex(char_digest, char_digest + sizeof(boost::uuids::detail::md5::digest_type), std::back_inserter(result)); + this->filament_id = "P" + result.substr(0, 7); + BOOST_LOG_TRIVIAL(info) << "Preset::save: generated filament_id='" << this->filament_id << "' for user preset '" << this->name << "'"; + } + //BBS: change to json format //this->config.save(this->file); std::string from_str;