diff --git a/src/bonsai/bonsai/bim/module/spatial/__init__.py b/src/bonsai/bonsai/bim/module/spatial/__init__.py index bef4f21e46..49e93034f9 100644 --- a/src/bonsai/bonsai/bim/module/spatial/__init__.py +++ b/src/bonsai/bonsai/bim/module/spatial/__init__.py @@ -33,6 +33,7 @@ classes = ( operator.ReferenceStructure, operator.RemoveContainer, operator.SelectContainer, + operator.SelectDecomposedElement, operator.SelectDecomposedElements, operator.SelectProduct, operator.SelectSimilarContainer, diff --git a/src/bonsai/bonsai/bim/module/spatial/operator.py b/src/bonsai/bonsai/bim/module/spatial/operator.py index 298936b4c0..a592eb8843 100644 --- a/src/bonsai/bonsai/bim/module/spatial/operator.py +++ b/src/bonsai/bonsai/bim/module/spatial/operator.py @@ -265,6 +265,17 @@ class ToggleContainerElement(bpy.types.Operator): return {"FINISHED"} +class SelectDecomposedElement(bpy.types.Operator, tool.Ifc.Operator): + bl_idname = "bim.select_decomposed_element" + bl_label = "Select Decomposed Element" + bl_options = {"REGISTER", "UNDO"} + element: bpy.props.IntProperty() + + def _execute(self, context): + if self.element: + core.select_decomposed_element(tool.Ifc, tool.Spatial, element=tool.Ifc.get().by_id(self.element)) + + class SelectDecomposedElements(bpy.types.Operator, tool.Ifc.Operator): bl_idname = "bim.select_decomposed_elements" bl_label = "Select Children" diff --git a/src/bonsai/bonsai/bim/module/spatial/ui.py b/src/bonsai/bonsai/bim/module/spatial/ui.py index 8340eb2bb5..33a5d87c07 100644 --- a/src/bonsai/bonsai/bim/module/spatial/ui.py +++ b/src/bonsai/bonsai/bim/module/spatial/ui.py @@ -171,6 +171,11 @@ class BIM_PT_spatial_decomposition(Panel): ) row.prop(self.props, "should_include_children", text="", icon="OUTLINER") row.operator("bim.assign_container", icon="FOLDER_REDIRECT", text="").container = ifc_definition_id + op = row.operator("bim.select_decomposed_element", icon="OBJECT_DATA", text="") + if active_element := self.props.active_element: + op.element = active_element.ifc_definition_id + else: + op.element = 0 op = row.operator("bim.select_decomposed_elements", icon="RESTRICT_SELECT_OFF", text="") op.container = ifc_definition_id diff --git a/src/bonsai/bonsai/core/spatial.py b/src/bonsai/bonsai/core/spatial.py index ae05fdef08..f813d21709 100644 --- a/src/bonsai/bonsai/core/spatial.py +++ b/src/bonsai/bonsai/core/spatial.py @@ -159,6 +159,10 @@ def select_decomposed_elements( spatial.select_products(elements) +def select_decomposed_element(ifc: tool.Ifc, spatial: tool.Spatial, element: ifcopenshell.entity_instance) -> None: + spatial.set_active_object(ifc.get_object(element)) + + def generate_space(ifc: tool.Ifc, model: tool.Model, root: tool.Root, spatial: tool.Spatial, type: tool.Type) -> None: if not root.get_default_container(): raise NoDefaultContainer()