diff --git a/backend/app/api/routes/printers.py b/backend/app/api/routes/printers.py index 3f924859f..fa890f1d2 100644 --- a/backend/app/api/routes/printers.py +++ b/backend/app/api/routes/printers.py @@ -595,6 +595,15 @@ async def get_printer_cover( possible_filenames.append(f"{subtask_name}.gcode.3mf") possible_filenames.append(f"{subtask_name}.3mf") + # Also try with spaces converted to underscores (Bambu Studio may normalize filenames) + if " " in subtask_name: + normalized = subtask_name.replace(" ", "_") + if normalized.endswith(".3mf"): + possible_filenames.append(normalized) + else: + possible_filenames.append(f"{normalized}.gcode.3mf") + possible_filenames.append(f"{normalized}.3mf") + # Build list of all remote paths to try remote_paths = [] for filename in possible_filenames: @@ -1574,6 +1583,15 @@ async def get_printable_objects( possible_filenames.append(f"{subtask_name}.gcode.3mf") possible_filenames.append(f"{subtask_name}.3mf") + # Also try with spaces converted to underscores (Bambu Studio may normalize filenames) + if " " in subtask_name: + normalized = subtask_name.replace(" ", "_") + if normalized.endswith(".3mf"): + possible_filenames.append(normalized) + else: + possible_filenames.append(f"{normalized}.gcode.3mf") + possible_filenames.append(f"{normalized}.3mf") + # Download 3MF from printer temp_path = settings.archive_dir / "temp" / f"objects_{printer_id}_{possible_filenames[0]}" temp_path.parent.mkdir(parents=True, exist_ok=True) diff --git a/backend/app/main.py b/backend/app/main.py index 5f534411e..e36d5cc89 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -1002,6 +1002,13 @@ async def on_print_start(printer_id: int, data: dict): possible_names.append(f"{fname}.gcode.3mf") possible_names.append(f"{fname}.3mf") + # Also try with spaces converted to underscores (Bambu Studio may normalize filenames) + space_variants = [] + for name in possible_names: + if " " in name: + space_variants.append(name.replace(" ", "_")) + possible_names.extend(space_variants) + # Remove duplicates while preserving order seen = set() possible_names = [x for x in possible_names if not (x in seen or seen.add(x))] @@ -1085,7 +1092,10 @@ async def on_print_start(printer_id: int, data: dict): if f.get("is_directory"): continue fname = f.get("name", "") - if fname.endswith(".3mf") and search_term in fname.lower(): + # Normalize both for comparison (spaces and underscores are equivalent) + fname_normalized = fname.lower().replace(" ", "_") + search_normalized = search_term.replace(" ", "_") + if fname.endswith(".3mf") and search_normalized in fname_normalized: logger.info(f"Found matching file in {search_dir}: {fname}") temp_path = app_settings.archive_dir / "temp" / fname temp_path.parent.mkdir(parents=True, exist_ok=True)