From 037b5d1bc11d0cba6bd69af33a7ea53c49bc72ee Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Wed, 30 Oct 2024 18:45:45 +0500 Subject: [PATCH] Spatial container drop down to show only spatial objects Example - https://i.imgur.com/v8p4D57.png (it's ignoring walls). Since we now filter valid elements in poll_container_obj, then there is no need to check it twice in update_container_obj. --- src/bonsai/bonsai/bim/module/spatial/prop.py | 33 ++++++-------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/src/bonsai/bonsai/bim/module/spatial/prop.py b/src/bonsai/bonsai/bim/module/spatial/prop.py index 20a1cc1d18..24e021709e 100644 --- a/src/bonsai/bonsai/bim/module/spatial/prop.py +++ b/src/bonsai/bonsai/bim/module/spatial/prop.py @@ -80,24 +80,6 @@ def update_element_mode(self: "BIMSpatialDecompositionProperties", context: bpy. tool.Spatial.load_contained_elements() -def update_container_obj(self: "BIMObjectSpatialProperties", context: bpy.types.Context) -> None: - if self.container_obj is None or not (obj := context.active_object): - return - if not (element := tool.Ifc.get_entity(self.container_obj)): - self.container_obj = None - return - if tool.Spatial.can_contain(element, obj): - return - if ( - (container := ifcopenshell.util.element.get_container(element)) - and (container_obj := tool.Ifc.get_object(container)) - and tool.Spatial.can_contain(container, obj) - ): - self.container_obj = container_obj - return - self.container_obj = None - - def update_grid_is_locked(self, context): if not tool.Ifc.get(): return @@ -140,15 +122,20 @@ def update_grid_is_visible(self: "BIMGridProperties", context: bpy.types.Context bpy.ops.bim.toggle_grids(is_visible=self.is_visible) -def poll_container_obj(self, obj): - return obj is None or tool.Ifc.get_entity(obj) +def poll_container_obj(self: "BIMObjectSpatialProperties", container_obj: bpy.types.Object) -> bool: + obj = self.id_data + if ( + (container := tool.Ifc.get_entity(container_obj)) + and (tool.Ifc.get_entity(obj)) + and tool.Spatial.can_contain(container, obj) + ): + return True + return False class BIMObjectSpatialProperties(PropertyGroup): is_editing: BoolProperty(name="Is Editing") - container_obj: PointerProperty( - type=bpy.types.Object, name="Container", update=update_container_obj, poll=poll_container_obj - ) + container_obj: PointerProperty(type=bpy.types.Object, name="Container", poll=poll_container_obj) class BIMContainer(PropertyGroup):