diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index f127040b29..86614a6a79 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -287,6 +287,7 @@ class SelectSimilarContainer(bpy.types.Operator): bl_description = "Recursively selects all objects in the container.\n\nCtrl+click to select only one level deep\nAlt+click to also unhide hidden objects (viewport and local hide)" bl_options = {"REGISTER", "UNDO"} + container: bpy.props.IntProperty(default=0) is_recursive: bpy.props.BoolProperty(default=True) should_unhide: bpy.props.BoolProperty(default=False, options={"SKIP_SAVE"}) @@ -297,10 +298,17 @@ class SelectSimilarContainer(bpy.types.Operator): return self.execute(context) def execute(self, context): + if self.container: + container = tool.Ifc.get().by_id(self.container) + elif element := tool.Ifc.get_entity(context.active_object): + container = ifcopenshell.util.element.get_container(element) + else: + return {"CANCELLED"} + if not container: + return {"CANCELLED"} core.select_similar_container( - tool.Ifc, tool.Spatial, - obj=context.active_object, + container=container, is_recursive=self.is_recursive, should_unhide=self.should_unhide, ) diff --git a/src/bonsai/bonsai/bim/module/spatial/ui.py b/src/bonsai/bonsai/bim/module/spatial/ui.py index 3a4a771e01..051fcaab77 100644 --- a/src/bonsai/bonsai/bim/module/spatial/ui.py +++ b/src/bonsai/bonsai/bim/module/spatial/ui.py @@ -139,7 +139,7 @@ class BIM_PT_spatial_decomposition(Panel): op = col.operator("bim.set_default_container", icon="OUTLINER_COLLECTION", text="Set Default") op.container = ifc_definition_id - if tool.Blender.get_addon_preferences().container_hide_show_isolate: + if tool.Blender.get_addon_preferences().show_container_tools: op = row.operator("bim.set_container_visibility", icon="FULLSCREEN_EXIT", text="") op.mode = "ISOLATE" op.container = ifc_definition_id @@ -152,7 +152,10 @@ class BIM_PT_spatial_decomposition(Panel): # The only operator that's enabled for IfcProject. col = row.column(align=True) - col.operator("bim.select_container", icon="OBJECT_DATA", text="").container = ifc_definition_id + row_ = col.row(align=True) + row_.operator("bim.select_container", icon="OBJECT_DATA", text="").container = ifc_definition_id + if tool.Blender.get_addon_preferences().show_container_tools: + row_.operator("bim.select_similar_container", icon="RESTRICT_SELECT_OFF", text="").container = ifc_definition_id col = row.column(align=True) op = col.operator("bim.delete_container", icon="X", text="") diff --git a/src/bonsai/bonsai/bim/ui.py b/src/bonsai/bonsai/bim/ui.py index 09eee51401..ff904fdcdd 100644 --- a/src/bonsai/bonsai/bim/ui.py +++ b/src/bonsai/bonsai/bim/ui.py @@ -714,9 +714,9 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): description="Default parameters for BIM elements", ) - container_hide_show_isolate: BoolProperty( - name="Container hide/show/isolate", - description="Enable container hide/show/isolate feature in the UI", + show_container_tools: BoolProperty( + name="Show Container Tools (Select, Hide, Show, Isolate)", + description="Enable container select, hide/show/isolate tools in the UI", default=False, ) @@ -786,7 +786,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): pset_dir: str doc: DocPreferences default_parameters: DefaultParameters - container_hide_show_isolate: bool + show_container_tools: bool chain_filter_with_set_operations: bool save_metadata_blend_file: bool metadata_blend_file_suffix: str @@ -984,7 +984,7 @@ class BIM_ADDON_preferences(bpy.types.AddonPreferences): layout.prop(self, "bsdd_baseurl") def draw_extras_settings(self, layout: bpy.types.UILayout, context: bpy.types.Context) -> None: - layout.prop(self, "container_hide_show_isolate") + layout.prop(self, "show_container_tools") row = layout.row(align=True) row.prop(self, "chain_filter_with_set_operations") row.operator("bim.open_uri", text="", icon="HELP").uri = "https://community.osarch.org/discussion/3270" diff --git a/src/bonsai/bonsai/core/spatial.py b/src/bonsai/bonsai/core/spatial.py index 56c07f5e24..3c0203b39c 100644 --- a/src/bonsai/bonsai/core/spatial.py +++ b/src/bonsai/bonsai/core/spatial.py @@ -120,17 +120,12 @@ def select_container( def select_similar_container( - ifc: type[tool.Ifc], spatial: type[tool.Spatial], - obj: bpy.types.Object, + container: ifcopenshell.entity_instance, is_recursive: bool = True, should_unhide: bool = False, ) -> None: - element = ifc.get_entity(obj) - if element: - spatial.select_products( - spatial.get_decomposed_elements(spatial.get_container(element), is_recursive), unhide=should_unhide - ) + spatial.select_products(spatial.get_decomposed_elements(container, is_recursive), unhide=should_unhide) def select_product(spatial: type[tool.Spatial], product: ifcopenshell.entity_instance) -> None: