From 553003e664e06285493fa8cf80f6b6e5a4a2d826 Mon Sep 17 00:00:00 2001 From: Ryan Schultz Date: Sat, 28 Jun 2025 13:16:51 -0500 Subject: [PATCH] Closes #6748: An option, when running bim.select_similar_container() to only select those objects in the immediate container --- src/bonsai/bonsai/bim/module/spatial/operator.py | 16 +++++++++++++++- src/bonsai/bonsai/core/spatial.py | 9 +++++++-- src/bonsai/bonsai/tool/spatial.py | 4 ++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index 3ed52d9325..33e1b23595 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -305,10 +305,24 @@ class SelectContainer(bpy.types.Operator): class SelectSimilarContainer(bpy.types.Operator): bl_idname = "bim.select_similar_container" bl_label = "Select Similar Container" + bl_description = "Recurvisevly selects all objects in the container.\n\nCtrl+click to select only one level deep" bl_options = {"REGISTER", "UNDO"} + is_recursive: bpy.props.BoolProperty(default=True) + + def invoke(self, context, event): + if event.type == "LEFTMOUSE" and event.ctrl: + self.is_recursive = False + return self.execute(context) + def execute(self, context): - core.select_similar_container(tool.Ifc, tool.Spatial, obj=context.active_object) + core.select_similar_container( + tool.Ifc, + tool.Spatial, + obj=context.active_object, + is_recursive=self.is_recursive, + ) + self.is_recursive = True # <-- forcibly reset return {"FINISHED"} diff --git a/src/bonsai/bonsai/core/spatial.py b/src/bonsai/bonsai/core/spatial.py index 782395d04b..e13ea8cfca 100644 --- a/src/bonsai/bonsai/core/spatial.py +++ b/src/bonsai/bonsai/core/spatial.py @@ -110,10 +110,15 @@ def select_container( spatial.set_active_object(ifc.get_object(container), selection_mode=selection_mode) -def select_similar_container(ifc: type[tool.Ifc], spatial: type[tool.Spatial], obj: bpy.types.Object) -> None: +def select_similar_container( + ifc: type[tool.Ifc], + spatial: type[tool.Spatial], + obj: bpy.types.Object, + is_recursive: bool = True, +) -> None: element = ifc.get_entity(obj) if element: - spatial.select_products(spatial.get_decomposed_elements(spatial.get_container(element))) + spatial.select_products(spatial.get_decomposed_elements(spatial.get_container(element), is_recursive)) def select_product(spatial: type[tool.Spatial], product: ifcopenshell.entity_instance) -> None: diff --git a/src/bonsai/bonsai/tool/spatial.py b/src/bonsai/bonsai/tool/spatial.py index e94c15850a..851560c969 100644 --- a/src/bonsai/bonsai/tool/spatial.py +++ b/src/bonsai/bonsai/tool/spatial.py @@ -125,8 +125,8 @@ class Spatial(bonsai.core.tool.Spatial): return ifcopenshell.util.element.get_container(element) @classmethod - def get_decomposed_elements(cls, container: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: - return ifcopenshell.util.element.get_decomposition(container) + def get_decomposed_elements(cls, container: ifcopenshell.entity_instance, is_recursive=True) -> list[ifcopenshell.entity_instance]: + return ifcopenshell.util.element.get_decomposition(container, is_recursive=is_recursive) @classmethod def get_object_matrix(cls, obj: bpy.types.Object) -> Matrix: