fix couple issues after ce9e4f285 #4843

1) BBIM was failing to unregister properly.
2) Failed to link materials on load.
3) Failed to purge IFC file.
4) Error changing style name
This commit is contained in:
Andrej730
2024-06-26 11:27:10 +05:00
parent 7bbc81b7c3
commit 78e81542d9
4 changed files with 16 additions and 19 deletions
@@ -283,7 +283,6 @@ def unregister():
del bpy.types.Scene.BIMProperties
del bpy.types.Collection.BIMCollectionProperties
del bpy.types.Object.BIMObjectProperties
del bpy.types.Material.BIMObjectProperties
del bpy.types.Material.BIMMaterialProperties
del bpy.types.Mesh.BIMMeshProperties
del bpy.types.Curve.BIMMeshProperties
+11 -6
View File
@@ -205,19 +205,24 @@ class IfcStore:
def relink_object(obj: IFC_CONNECTED_TYPE) -> None:
if not obj:
return
if obj.BIMObjectProperties.ifc_definition_id:
if isinstance(obj, bpy.types.Object):
ifc_definition_id = obj.BIMObjectProperties.ifc_definition_id
if not ifc_definition_id:
return
try:
element = IfcStore.get_file().by_id(obj.BIMObjectProperties.ifc_definition_id)
except:
element = IfcStore.get_file().by_id(ifc_definition_id)
except RuntimeError:
return
data = OperationData(id=element.id(), obj=obj.name)
if hasattr(element, "GlobalId"):
data["guid"] = element.GlobalId
IfcStore.commit_link_element(data)
if hasattr(obj, "BIMMaterialProperties") and obj.BIMMaterialProperties.ifc_style_id:
return
else: # bpy.types.Material
ifc_definition_id = obj.BIMMaterialProperties.ifc_style_id
try:
element = IfcStore.get_file().by_id(obj.BIMMaterialProperties.ifc_style_id)
except:
element = IfcStore.get_file().by_id(ifc_definition_id)
except RuntimeError:
return
data = OperationData(id=element.id(), obj=obj.name)
IfcStore.commit_link_element(data)
@@ -90,12 +90,11 @@ class ConvertToBlender(bpy.types.Operator):
def execute(self, context):
for obj in bpy.data.objects:
if obj.type in {"MESH", "EMPTY"}:
obj.BIMObjectProperties.ifc_definition_id = 0
tool.Ifc.unlink(obj=obj)
if obj.data:
obj.data.BIMMeshProperties.ifc_definition_id = 0
for material in bpy.data.materials:
material.BIMObjectProperties.ifc_definition_id = 0
material.BIMMaterialProperties.ifc_style_id = 0
tool.Ifc.unlink(obj=material)
context.scene.BIMProperties.ifc_file = ""
context.scene.BIMDebugProperties.attributes.clear()
IfcStore.purge()
@@ -35,16 +35,10 @@ def sync_name(usecase_path, ifc_file, settings):
return
if isinstance(obj, bpy.types.Object):
new_name = "{}/{}".format(element.is_a(), settings["attributes"]["Name"] or "Unnamed")
collection = obj.BIMObjectProperties.collection
if collection:
collection.name = new_name
elif isinstance(obj, bpy.types.Material):
new_name = settings["attributes"]["Name"] or "Unnamed"
material = tool.Ifc.get_entity(obj)
if material and material != element:
material.Name = new_name
style = tool.Style.get_style(obj)
if style and style != element:
style.Name = new_name
collection = obj.BIMObjectProperties.collection
if collection:
collection.name = new_name
obj.name = new_name
blenderbim.bim.handler.refresh_ui_data()