From 15cf3f5afdb960c618b1ac4231edfb77c56b4ac5 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 23 Feb 2021 20:01:00 +1100 Subject: [PATCH] Fix bug where undo operations may invalidate an ID map and break everything --- src/ifcblenderexport/blenderbim/bim/handler.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/handler.py b/src/ifcblenderexport/blenderbim/bim/handler.py index d9f526eaad..7af2edb706 100644 --- a/src/ifcblenderexport/blenderbim/bim/handler.py +++ b/src/ifcblenderexport/blenderbim/bim/handler.py @@ -69,8 +69,21 @@ def ensureIfcExported(scene): @persistent def storeIdMap(scene): - bpy.context.scene.BIMProperties.id_map = json.dumps({k: v.name for k, v in IfcStore.id_map.items()}) - bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()}) + try: + bpy.context.scene.BIMProperties.id_map = json.dumps({k: v.name for k, v in IfcStore.id_map.items()}) + bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()}) + except: + # Regenerate maps. Is there a better solution for this? It seems fragile. + file = IfcStore.get_file() + IfcStore.id_map = { + o.ifc_definition_id: o.name for o in bpy.data.objects if o.BIMObjectProperties.ifc_definition_id + } + IfcStore.guid_map = { + file.by_id(i).GlobalId: n for i, n in IfcStore.id_map.items() if file.by_id(i).is_a("IfcRoot") + } + # Then attempt to store it again + bpy.context.scene.BIMProperties.id_map = json.dumps({k: v.name for k, v in IfcStore.id_map.items()}) + bpy.context.scene.BIMProperties.guid_map = json.dumps({k: v.name for k, v in IfcStore.guid_map.items()}) @persistent