diff --git a/src/bonsai/bonsai/bim/module/project/operator.py b/src/bonsai/bonsai/bim/module/project/operator.py index 8bad2e17d4..e4ac3c8dfb 100644 --- a/src/bonsai/bonsai/bim/module/project/operator.py +++ b/src/bonsai/bonsai/bim/module/project/operator.py @@ -1056,6 +1056,18 @@ class LoadProject(bpy.types.Operator, IFCFileSelector, ImportHelper): return tooltip def execute(self, context): + if (tool.Blender.get_addon_preferences().user_ui_customization + and self.should_start_fresh_session + and not self.is_advanced): + filepath = self.get_filepath() + metadata_path = Path(str(filepath) + ".metadata.blend") + if metadata_path.exists() and metadata_path.is_file(): + try: + bpy.ops.bim.load_blend_metadata_and_ifc(filepath=filepath) + return {"FINISHED"} + except Exception as e: + self.report({"WARNING"}, f"Failed to load metadata file, using regular load: {e}") + @persistent def load_handler(*args): bpy.app.handlers.load_post.remove(load_handler) @@ -1748,6 +1760,13 @@ class ExportIFC(bpy.types.Operator, ExportHelper): if save_blend_file: bpy.ops.wm.save_mainfile(filepath=bpy.data.filepath) bim_props.is_dirty = False + + if tool.Blender.get_addon_preferences().user_ui_customization: + try: + bpy.ops.bim.save_blend_metadata_file() + except Exception as e: + settings.logger.warning(f"Failed to save blend metadata file: {e}") + bonsai.bim.handler.refresh_ui_data() self.report( {"INFO"}, diff --git a/src/bonsai/bonsai/bim/module/project/ui.py b/src/bonsai/bonsai/bim/module/project/ui.py index c728908ed2..6296c9a984 100644 --- a/src/bonsai/bonsai/bim/module/project/ui.py +++ b/src/bonsai/bonsai/bim/module/project/ui.py @@ -331,18 +331,12 @@ class BIM_PT_project(Panel): col.prop(props, "ifc_file", text="") row.operator("bim.select_ifc_file", icon="FILE_FOLDER", text="") - # Blend metadata file UI - row = self.layout.row(align=True) - col = row.column() - col.enabled = False - # Show blend metadata file as a label, not editable - blendmetadata_path = "" - if props.ifc_file: - blendmetadata_path = props.ifc_file + ".blendmetadata" - col.label(text=blendmetadata_path) - row.operator("bim.save_blend_metadata_file", icon="FILE_TICK", text="") - row = self.layout.row(align=True) - row.operator("bim.load_blend_metadata_and_ifc", icon="FILE_REFRESH", text="Load Metadata + IFC") + if tool.Blender.get_addon_preferences().user_ui_customization: + 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}") class BIM_PT_new_project_wizard(Panel): diff --git a/src/bonsai/bonsai/bim/operator.py b/src/bonsai/bonsai/bim/operator.py index 5569f0ea1d..1a1c07bd3f 100644 --- a/src/bonsai/bonsai/bim/operator.py +++ b/src/bonsai/bonsai/bim/operator.py @@ -304,10 +304,14 @@ class LoadBlendMetadataAndIFC(bpy.types.Operator): bl_idname = "bim.load_blend_metadata_and_ifc" bl_label = "Load Blend Metadata and IFC" bl_options = {"REGISTER", "UNDO"} + filepath: bpy.props.StringProperty(name="IFC File Path", default="") def execute(self, context): - props = tool.Blender.get_bim_props() - ifc_file = getattr(props, "ifc_file", None) + ifc_file = self.filepath + if not ifc_file: + props = tool.Blender.get_bim_props() + ifc_file = getattr(props, "ifc_file", None) + if not ifc_file: self.report({"WARNING"}, "No IFC file path set.") return {"CANCELLED"} diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index 76cb29b991..4062991aa5 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -702,7 +702,12 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): description="Show mass and time units section in the new project wizard panel", default=False, ) - + 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", + default=False, + ) + chain_filter_with_set_operations: BoolProperty( name="NEW filter mode: Enable chained filters with set operations", description="Enable chaining search filters with set operations: ADD (union: combine sets), SUBTRACT (difference: remove from set), FILTER (intersection: only elements in both sets), with autocomplete suggestions for filter values", @@ -753,6 +758,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): mass_time_units_in_wizard: bool chain_filter_with_set_operations: bool default_filter_with_set_operations_for_globalid_and_class: bool + user_ui_customization: bool def draw(self, context: bpy.types.Context) -> None: layout = self.layout @@ -943,6 +949,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): row = box.row(align=True) row.prop(self, "default_filter_with_set_operations_for_globalid_and_class") row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/comment/27030" + layout.prop(self, "user_ui_customization") # Scene panel groups @@ -989,8 +996,8 @@ class BIM_PT_tabs(Panel): self.draw_tab_entry(row_left, "PACKAGE", "FM", True, aprops.tab == "FM") if get_tab_visibility("QUALITY"): self.draw_tab_entry(row_left, "COMMUNITY", "QUALITY", True, aprops.tab == "QUALITY") - if get_tab_visibility("BOOKMARK"): - self.draw_tab_entry(row_left, "SOLO_ON", "BOOKMARK", True, aprops.tab == "BOOKMARK") # New BOOKMARK tab + if tool.Blender.get_addon_preferences().user_ui_customization and get_tab_visibility("BOOKMARK"): + self.draw_tab_entry(row_left, "SOLO_ON", "BOOKMARK", True, aprops.tab == "BOOKMARK") row_left.operator("bim.switch_tab", text="", emboss=False, icon="UV_SYNC_SELECT") row_left = col_left.row(align=True) @@ -1010,16 +1017,17 @@ class BIM_PT_tabs(Panel): row_right = col_right.row(align=True) row_right.alignment = "RIGHT" - row_right.operator("bim.manage_tab_visibility", icon="PREFERENCES", text="") + if tool.Blender.get_addon_preferences().user_ui_customization: + row_right.operator("bim.manage_tab_visibility", icon="PREFERENCES", text="") row = self.layout.row(align=True) row.prop(aprops, "tab", text="") - # Add gear icons for all tabs except SWITCH_TAB - for tab in get_tab_names(): - if get_tab_visibility(tab): - if aprops.tab == tab: - row.operator("bim.manage_tab_panels", text="", icon="PREFERENCES").tab_name = tab + if tool.Blender.get_addon_preferences().user_ui_customization: + for tab in get_tab_names(): + if get_tab_visibility(tab): + if aprops.tab == tab: + row.operator("bim.manage_tab_panels", text="", icon="PREFERENCES").tab_name = tab if bonsai.REINSTALLED_BBIM_VERSION: box = self.layout.box()