diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp index f1d892134b..47921a2440 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.cpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.cpp @@ -579,6 +579,27 @@ bool MoonrakerPrinterAgent::fetch_filament_info(std::string dev_id) << (max_lane_index + 1) << " lanes"; int ams_count = (max_lane_index + 4) / 4; build_ams_payload(ams_count, max_lane_index, trays); + + // If every tray reported extruder_index, auto-populate physical_extruder_map + // so IMEX PA and temperature emission use the correct physical extruder qualifier. + // AFC publishes extruder_index=0 for all AFC lanes (they share one carriage) and + // extruder_index=N for independent direct-drive tools on separate carriages. + bool all_have_extruder_index = std::all_of(trays.begin(), trays.end(), + [](const AmsTrayData& t) { return t.extruder_index >= 0; }); + if (all_have_extruder_index) { + std::vector pem(max_lane_index + 1, 0); + for (const auto& tray : trays) + if (tray.slot_index >= 0 && tray.slot_index <= max_lane_index) + pem[tray.slot_index] = tray.extruder_index; + wxTheApp->CallAfter([pem]() { + auto* bundle = GUI::wxGetApp().preset_bundle; + if (!bundle) return; + auto& config = bundle->printers.get_edited_preset().config; + config.set_key_value("physical_extruder_map", new ConfigOptionInts(pem)); + BOOST_LOG_TRIVIAL(info) << "MoonrakerPrinterAgent: auto-populated physical_extruder_map from AFC extruder_index"; + }); + } + return true; } @@ -803,6 +824,10 @@ bool MoonrakerPrinterAgent::fetch_moonraker_filament_data(std::vector(); tray.has_filament = !tray.tray_type.empty(); auto* bundle = GUI::wxGetApp().preset_bundle; tray.tray_info_idx = bundle diff --git a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp index a37a6c3fd6..d8ab18ed2e 100644 --- a/src/slic3r/Utils/MoonrakerPrinterAgent.hpp +++ b/src/slic3r/Utils/MoonrakerPrinterAgent.hpp @@ -90,6 +90,7 @@ protected: // Tray data for AMS payload building struct AmsTrayData { int slot_index = 0; // 0-based slot index + int extruder_index = -1; // Physical extruder index from AFC extruder_index field (-1 = not provided) bool has_filament = false; std::string tray_type; // Material type (e.g., "PLA", "ASA") std::string tray_color; // Raw color (#RRGGBB, 0xRRGGBB, or RRGGBBAA)