Fix #2048. Fix bug where material and style IFC links were severed after reloading a saved Blender file

This commit is contained in:
Dion Moult
2022-05-01 09:41:03 +10:00
parent abcb492e5a
commit f54a5cf6e0
+17 -8
View File
@@ -232,20 +232,27 @@ class IfcStore:
@staticmethod @staticmethod
def relink_all_objects(): def relink_all_objects():
file = IfcStore.get_file() if not IfcStore.get_file():
if not file:
return return
for obj in bpy.data.objects: for obj in bpy.data.objects:
if not obj: IfcStore.relink_object(obj)
continue for obj in bpy.data.materials:
if not obj.BIMObjectProperties.ifc_definition_id: IfcStore.relink_object(obj)
continue
element = file.by_id(obj.BIMObjectProperties.ifc_definition_id) @staticmethod
def relink_object(obj):
if not obj:
return
if obj.BIMObjectProperties.ifc_definition_id:
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
data = {"id": element.id(), "obj": obj.name} data = {"id": element.id(), "obj": obj.name}
if hasattr(element, "GlobalId"): if hasattr(element, "GlobalId"):
data["guid"] = element.GlobalId data["guid"] = element.GlobalId
IfcStore.commit_link_element(data) IfcStore.commit_link_element(data)
if hasattr(obj, "BIMMaterialProperties") and obj.BIMMaterialProperties.ifc_style_id:
element = IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id)
data = {"id": element.id(), "obj": obj.name}
IfcStore.commit_link_element(data)
@staticmethod @staticmethod
def delete_element(element): def delete_element(element):
@@ -300,6 +307,8 @@ class IfcStore:
@staticmethod @staticmethod
def commit_link_element(data): def commit_link_element(data):
obj = bpy.data.objects.get(data["obj"]) obj = bpy.data.objects.get(data["obj"])
if not obj:
obj = bpy.data.materials.get(data["obj"])
IfcStore.id_map[data["id"]] = obj IfcStore.id_map[data["id"]] = obj
if "guid" in data: if "guid" in data:
IfcStore.guid_map[data["guid"]] = obj IfcStore.guid_map[data["guid"]] = obj