From 90cb56220f84f8e4cf39b90357d987cc17516072 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 15 Jun 2021 13:05:24 +1000 Subject: [PATCH] Fix #1524. Fixed bug where unlinking copied Blender objects didn't work. --- src/blenderbim/blenderbim/bim/handler.py | 3 ++- src/blenderbim/blenderbim/bim/ifc.py | 18 ++++++++++++------ .../blenderbim/bim/module/aggregate/ui.py | 2 ++ .../blenderbim/bim/module/attribute/ui.py | 2 ++ .../blenderbim/bim/module/boundary/ui.py | 2 ++ .../blenderbim/bim/module/classification/ui.py | 2 ++ .../blenderbim/bim/module/constraint/ui.py | 2 ++ .../blenderbim/bim/module/document/ui.py | 2 ++ .../blenderbim/bim/module/geometry/ui.py | 2 ++ .../blenderbim/bim/module/material/ui.py | 2 ++ .../blenderbim/bim/module/pset/ui.py | 4 ++++ .../blenderbim/bim/module/root/ui.py | 1 + .../blenderbim/bim/module/spatial/ui.py | 2 ++ .../blenderbim/bim/module/structural/ui.py | 8 ++++++++ .../blenderbim/bim/module/type/ui.py | 2 ++ .../blenderbim/bim/module/void/ui.py | 2 ++ 16 files changed, 49 insertions(+), 7 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/handler.py b/src/blenderbim/blenderbim/bim/handler.py index cb15a0ab81..11e86bea3b 100644 --- a/src/blenderbim/blenderbim/bim/handler.py +++ b/src/blenderbim/blenderbim/bim/handler.py @@ -60,7 +60,8 @@ def active_object_callback(): for obj in bpy.context.selected_objects: if not obj.BIMObjectProperties.ifc_definition_id: continue - if IfcStore.id_map[obj.BIMObjectProperties.ifc_definition_id] != obj: + stored_obj = IfcStore.get_element(obj.BIMObjectProperties.ifc_definition_id) + if stored_obj and stored_obj != obj: bpy.ops.bim.copy_class(obj=obj.name) diff --git a/src/blenderbim/blenderbim/bim/ifc.py b/src/blenderbim/blenderbim/bim/ifc.py index 363d1fe437..6f5cc2b384 100644 --- a/src/blenderbim/blenderbim/bim/ifc.py +++ b/src/blenderbim/blenderbim/bim/ifc.py @@ -84,13 +84,19 @@ class IfcStore: except: pass - if element: - del IfcStore.id_map[element.id()] - else: - del IfcStore.id_map[obj.BIMObjectProperties.ifc_definition_id] + try: + if element: + del IfcStore.id_map[element.id()] + else: + del IfcStore.id_map[obj.BIMObjectProperties.ifc_definition_id] + except: + pass - if element and hasattr(element, "GlobalId"): - del IfcStore.guid_map[element.GlobalId] + try: + if element and hasattr(element, "GlobalId"): + del IfcStore.guid_map[element.GlobalId] + except: + pass if obj: obj.BIMObjectProperties.ifc_definition_id = 0 diff --git a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py index 474b51c23f..d136bc9afc 100644 --- a/src/blenderbim/blenderbim/bim/module/aggregate/ui.py +++ b/src/blenderbim/blenderbim/bim/module/aggregate/ui.py @@ -16,6 +16,8 @@ class BIM_PT_aggregate(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcObjectDefinition"): return False if props.ifc_definition_id not in Data.products: diff --git a/src/blenderbim/blenderbim/bim/module/attribute/ui.py b/src/blenderbim/blenderbim/bim/module/attribute/ui.py index 6e6c4c08a6..2a12aa343d 100644 --- a/src/blenderbim/blenderbim/bim/module/attribute/ui.py +++ b/src/blenderbim/blenderbim/bim/module/attribute/ui.py @@ -78,6 +78,8 @@ class BIM_PT_object_attributes(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) def draw(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/boundary/ui.py b/src/blenderbim/blenderbim/bim/module/boundary/ui.py index cafe32f382..4e0886a054 100644 --- a/src/blenderbim/blenderbim/bim/module/boundary/ui.py +++ b/src/blenderbim/blenderbim/bim/module/boundary/ui.py @@ -20,6 +20,8 @@ class BIM_PT_boundary(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if IfcStore.get_file().by_id(props.ifc_definition_id).is_a() not in ["IfcSpace", "IfcExternalSpatialElement"]: return False return True diff --git a/src/blenderbim/blenderbim/bim/module/classification/ui.py b/src/blenderbim/blenderbim/bim/module/classification/ui.py index d0b65021a8..032a7cd022 100644 --- a/src/blenderbim/blenderbim/bim/module/classification/ui.py +++ b/src/blenderbim/blenderbim/bim/module/classification/ui.py @@ -70,6 +70,8 @@ class BIM_PT_classification_references(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) def draw(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/constraint/ui.py b/src/blenderbim/blenderbim/bim/module/constraint/ui.py index c6132dc43d..2a0ae2d6cd 100644 --- a/src/blenderbim/blenderbim/bim/module/constraint/ui.py +++ b/src/blenderbim/blenderbim/bim/module/constraint/ui.py @@ -64,6 +64,8 @@ class BIM_PT_object_constraints(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) def draw(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/document/ui.py b/src/blenderbim/blenderbim/bim/module/document/ui.py index 1893fb620e..0bbafafb77 100644 --- a/src/blenderbim/blenderbim/bim/module/document/ui.py +++ b/src/blenderbim/blenderbim/bim/module/document/ui.py @@ -68,6 +68,8 @@ class BIM_PT_object_documents(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return bool(context.active_object.BIMObjectProperties.ifc_definition_id) def draw(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/geometry/ui.py b/src/blenderbim/blenderbim/bim/module/geometry/ui.py index 67c7fedf77..5378d33c62 100644 --- a/src/blenderbim/blenderbim/bim/module/geometry/ui.py +++ b/src/blenderbim/blenderbim/bim/module/geometry/ui.py @@ -14,6 +14,8 @@ class BIM_PT_representations(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return IfcStore.get_file() def draw(self, context): diff --git a/src/blenderbim/blenderbim/bim/module/material/ui.py b/src/blenderbim/blenderbim/bim/module/material/ui.py index 17dc5f1450..0c21497055 100644 --- a/src/blenderbim/blenderbim/bim/module/material/ui.py +++ b/src/blenderbim/blenderbim/bim/module/material/ui.py @@ -36,6 +36,8 @@ class BIM_PT_object_material(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not hasattr(IfcStore.get_file().by_id(props.ifc_definition_id), "HasAssociations"): return False return True diff --git a/src/blenderbim/blenderbim/bim/module/pset/ui.py b/src/blenderbim/blenderbim/bim/module/pset/ui.py index ff1ea46e5c..f3f257b8bb 100644 --- a/src/blenderbim/blenderbim/bim/module/pset/ui.py +++ b/src/blenderbim/blenderbim/bim/module/pset/ui.py @@ -101,6 +101,8 @@ class BIM_PT_object_psets(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if props.ifc_definition_id not in Data.products: Data.load(IfcStore.get_file(), props.ifc_definition_id) if not Data.products[props.ifc_definition_id]: @@ -144,6 +146,8 @@ class BIM_PT_object_qtos(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if props.ifc_definition_id not in Data.products: Data.load(IfcStore.get_file(), props.ifc_definition_id) if not Data.products[props.ifc_definition_id]: diff --git a/src/blenderbim/blenderbim/bim/module/root/ui.py b/src/blenderbim/blenderbim/bim/module/root/ui.py index bad4a43fc6..f698b9ca75 100644 --- a/src/blenderbim/blenderbim/bim/module/root/ui.py +++ b/src/blenderbim/blenderbim/bim/module/root/ui.py @@ -25,6 +25,7 @@ class BIM_PT_class(Panel): row = self.layout.row(align=True) row.label(text="IFC Element Not Found") row.operator("bim.unlink_object", icon="UNLINKED", text="") + return if props.is_reassigning_class: row = self.layout.row(align=True) row.operator("bim.reassign_class", icon="CHECKMARK") diff --git a/src/blenderbim/blenderbim/bim/module/spatial/ui.py b/src/blenderbim/blenderbim/bim/module/spatial/ui.py index b54ce3606e..a5710949f4 100644 --- a/src/blenderbim/blenderbim/bim/module/spatial/ui.py +++ b/src/blenderbim/blenderbim/bim/module/spatial/ui.py @@ -17,6 +17,8 @@ class BIM_PT_spatial(Panel): oprops = context.active_object.BIMObjectProperties if not oprops.ifc_definition_id: return False + if not IfcStore.get_element(oprops.ifc_definition_id): + return False if oprops.ifc_definition_id not in Data.products: Data.load(IfcStore.get_file(), oprops.ifc_definition_id) if not Data.products[oprops.ifc_definition_id]: diff --git a/src/blenderbim/blenderbim/bim/module/structural/ui.py b/src/blenderbim/blenderbim/bim/module/structural/ui.py index 0e7f37f834..9da00e38fa 100644 --- a/src/blenderbim/blenderbim/bim/module/structural/ui.py +++ b/src/blenderbim/blenderbim/bim/module/structural/ui.py @@ -76,6 +76,8 @@ class BIM_PT_structural_boundary_conditions(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True @@ -106,6 +108,8 @@ class BIM_PT_connected_structural_members(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True @@ -160,6 +164,8 @@ class BIM_PT_structural_member(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralMember"): return False return True @@ -198,6 +204,8 @@ class BIM_PT_structural_connection(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if not IfcStore.get_file().by_id(props.ifc_definition_id).is_a("IfcStructuralConnection"): return False return True diff --git a/src/blenderbim/blenderbim/bim/module/type/ui.py b/src/blenderbim/blenderbim/bim/module/type/ui.py index bdee759124..564afbc969 100644 --- a/src/blenderbim/blenderbim/bim/module/type/ui.py +++ b/src/blenderbim/blenderbim/bim/module/type/ui.py @@ -15,6 +15,8 @@ class BIM_PT_type(Panel): props = context.active_object.BIMObjectProperties if not props.ifc_definition_id: return False + if not IfcStore.get_element(props.ifc_definition_id): + return False if props.ifc_definition_id not in Data.products: Data.load(IfcStore.get_file(), props.ifc_definition_id) if not Data.products[props.ifc_definition_id]: diff --git a/src/blenderbim/blenderbim/bim/module/void/ui.py b/src/blenderbim/blenderbim/bim/module/void/ui.py index 20ba1fdb99..48c29cdcdc 100644 --- a/src/blenderbim/blenderbim/bim/module/void/ui.py +++ b/src/blenderbim/blenderbim/bim/module/void/ui.py @@ -14,6 +14,8 @@ class BIM_PT_voids(Panel): @classmethod def poll(cls, context): + if not IfcStore.get_element(context.active_object.BIMObjectProperties.ifc_definition_id): + return False return IfcStore.get_file() def draw(self, context):