diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 94d7279daa..64d6877757 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1062,10 +1062,15 @@ class LoadProject(bpy.types.Operator, IFCFileSelector, ImportHelper): and not self.is_advanced ): filepath = self.get_filepath() - metadata_path = Path(str(filepath) + ".metadata.blend") + suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix + if str(filepath).lower().endswith(".ifc"): + metadata_path = Path(str(filepath)[:-4] + suffix) + else: + metadata_path = Path(str(filepath) + suffix) if metadata_path.exists() and metadata_path.is_file(): try: bpy.ops.bim.load_blend_metadata_and_ifc(filepath=filepath) + self.report({"INFO"}, f"Loaded metadata file: {metadata_path.name}") return {"FINISHED"} except Exception as e: self.report({"WARNING"}, f"Failed to load metadata file, using regular load: {e}") @@ -1763,7 +1768,11 @@ class ExportIFC(bpy.types.Operator, ExportHelper): if tool.Blender.get_addon_preferences().save_metadata_blend_file: try: bpy.ops.bim.save_blend_metadata_file() - blendmetadata_path = output_file + ".metadata.blend" + suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix + if output_file.lower().endswith(".ifc"): + blendmetadata_path = output_file[:-4] + suffix + else: + blendmetadata_path = output_file + suffix self.report( {"INFO"}, f'IFC Project "{os.path.basename(output_file)}" And Metadata File Saved to: {os.path.basename(blendmetadata_path)}', diff --git a/src/bonsai/bonsai/bim/module/project/ui.py b/src/bonsai/bonsai/bim/module/project/ui.py index fa45494e0f..5d4f3f695b 100644 --- a/src/bonsai/bonsai/bim/module/project/ui.py +++ b/src/bonsai/bonsai/bim/module/project/ui.py @@ -332,10 +332,14 @@ class BIM_PT_project(Panel): row.operator("bim.select_ifc_file", icon="FILE_FOLDER", text="") if tool.Blender.get_addon_preferences().save_metadata_blend_file: + suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix + if props.ifc_file.lower().endswith(".ifc"): + metadata_filename = os.path.basename(props.ifc_file)[:-4] + suffix + else: + metadata_filename = os.path.basename(props.ifc_file) + suffix row = self.layout.row(align=True) col = row.column() col.enabled = False - metadata_filename = os.path.basename(props.ifc_file) + ".metadata.blend" col.label(text=f"Saving session data to: {metadata_filename}") diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index ffe2e4f662..0b7dcd917e 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -260,7 +260,11 @@ class SaveBlendMetadataFile(bpy.types.Operator): self.report({"WARNING"}, "No IFC file path set.") return {"CANCELLED"} - blendmetadata_path = ifc_file + ".metadata.blend" + suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix + if ifc_file.lower().endswith(".ifc"): + blendmetadata_path = ifc_file[:-4] + suffix + else: + blendmetadata_path = ifc_file + suffix ifc_dir = os.path.dirname(ifc_file) temp_path = os.path.join(ifc_dir, "__temp_blendmetadata.blend") @@ -376,7 +380,11 @@ class LoadBlendMetadataAndIFC(bpy.types.Operator): self.report({"WARNING"}, "No IFC file path set.") return {"CANCELLED"} - metadata_path = ifc_file + ".metadata.blend" + suffix = tool.Blender.get_addon_preferences().metadata_blend_file_suffix + if ifc_file.lower().endswith(".ifc"): + metadata_path = ifc_file[:-4] + suffix + else: + metadata_path = ifc_file + suffix # Open the metadata blend file bpy.ops.wm.open_mainfile(filepath=metadata_path) # After loading metadata, clear blend warning (no geometry loaded yet) diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index 338c766b81..e9ab0b446c 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -715,13 +715,18 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): ) save_metadata_blend_file: BoolProperty( - name="Save non ifc data to .metadata.blend File", - description="Save session data (window layout, settings) to a .metadata.blend file alongside the IFC file. This file is automatically loaded when opening the project.", + name="Save non ifc data to metadata blend File", + description="Save session data (window layout, settings) to a metadata blend file alongside the IFC file. This file is automatically loaded when opening the project.", default=False, ) + metadata_blend_file_suffix: StringProperty( + name="Metadata File Suffix", + description="Custom suffix for the metadata blend file. Will be appended to the filename (without .ifc).", + default=".ifc.metadata.blend", + ) user_ui_customization: BoolProperty( name="User UI Customization", - description="Enable user interface customization features (hide/show tabs and panels, bookmark panels) and save the session settings as part of the .metadata.blend file", + description="Enable user interface customization features (hide/show tabs and panels, bookmark panels) and save the session settings as part of the metadata blend file", default=False, ) @@ -958,6 +963,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/comment/27030" layout.prop(self, "save_metadata_blend_file") if self.save_metadata_blend_file: + row = layout.row() + row.separator() + row.prop(self, "metadata_blend_file_suffix") row = layout.row() row.separator() row.prop(self, "user_ui_customization")