Closes #6748: An option, when running bim.select_similar_container() to only select those objects in the immediate container

This commit is contained in:
Ryan Schultz
2025-06-28 13:16:51 -05:00
parent 524561a398
commit 553003e664
3 changed files with 24 additions and 5 deletions
@@ -305,10 +305,24 @@ class SelectContainer(bpy.types.Operator):
class SelectSimilarContainer(bpy.types.Operator): class SelectSimilarContainer(bpy.types.Operator):
bl_idname = "bim.select_similar_container" bl_idname = "bim.select_similar_container"
bl_label = "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"} 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): 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"} return {"FINISHED"}
+7 -2
View File
@@ -110,10 +110,15 @@ def select_container(
spatial.set_active_object(ifc.get_object(container), selection_mode=selection_mode) 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) element = ifc.get_entity(obj)
if element: 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: def select_product(spatial: type[tool.Spatial], product: ifcopenshell.entity_instance) -> None:
+2 -2
View File
@@ -125,8 +125,8 @@ class Spatial(bonsai.core.tool.Spatial):
return ifcopenshell.util.element.get_container(element) return ifcopenshell.util.element.get_container(element)
@classmethod @classmethod
def get_decomposed_elements(cls, container: ifcopenshell.entity_instance) -> list[ifcopenshell.entity_instance]: def get_decomposed_elements(cls, container: ifcopenshell.entity_instance, is_recursive=True) -> list[ifcopenshell.entity_instance]:
return ifcopenshell.util.element.get_decomposition(container) return ifcopenshell.util.element.get_decomposition(container, is_recursive=is_recursive)
@classmethod @classmethod
def get_object_matrix(cls, obj: bpy.types.Object) -> Matrix: def get_object_matrix(cls, obj: bpy.types.Object) -> Matrix: