From c156100be2174cb1ea490a931678033705d945a1 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 8 Jan 2024 15:53:10 +0500 Subject: [PATCH] Fix breaking spatial containers UI when spatial container is deleted E.g. if you had some container selected in `active_container_id` and then it got deleted UI would break and won't allow to reload the spatial manger until you reload .ifc completely --- src/blenderbim/blenderbim/bim/module/spatial/data.py | 8 ++++---- src/blenderbim/blenderbim/bim/module/spatial/ui.py | 3 ++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/spatial/data.py b/src/blenderbim/blenderbim/bim/module/spatial/data.py index 930a19b84a..78d3777295 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/data.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/data.py @@ -32,7 +32,7 @@ class SpatialData: @classmethod def load(cls): cls.data = { - "parent_container_id": cls.get_parent_container_id(), + "parent_container_id": cls.parent_container_id(), "is_directly_contained": cls.is_directly_contained(), "label": cls.label(), "references": cls.references(), @@ -55,12 +55,12 @@ class SpatialData: return results @classmethod - def get_parent_container_id(cls): + def parent_container_id(cls): container_id = bpy.context.scene.BIMSpatialProperties.active_container_id if not container_id: return - container = tool.Ifc.get().by_id(container_id) - if container.is_a("IfcProject"): + container = tool.Ifc.get_entity_by_id(container_id) + if not container or container.is_a("IfcProject"): return return container.Decomposes[0].RelatingObject.id() diff --git a/src/blenderbim/blenderbim/bim/module/spatial/ui.py b/src/blenderbim/blenderbim/bim/module/spatial/ui.py index 60112ac7d9..c697ebb8e2 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/ui.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/ui.py @@ -121,7 +121,8 @@ class BIM_PT_SpatialManager(Panel): row = self.layout.row() row.alignment = "RIGHT" row.operator("bim.select_decomposed_elements", icon="RESTRICT_SELECT_OFF", text="Select Children") - if SpatialData.data["containers"][ifc_definition_id]["type"] in ["IfcBuildingStorey", "IfcBuilding"]: + spatial_data = SpatialData.data["containers"].get(ifc_definition_id, None) + if spatial_data and spatial_data["type"] in ["IfcBuildingStorey", "IfcBuilding"]: row.operator("bim.add_building_storey", icon="ADD", text="Add storey").part_class = "IfcBuildingStorey" row.operator("bim.delete_container", icon="X", text="Delete").container = ifc_definition_id self.layout.template_list(