Fix error during class reassignment after 43cc7a0

This commit is contained in:
Andrej730
2025-02-24 14:51:45 +05:00
parent e79a85a4fd
commit 1d2ac9426d
+11 -2
View File
@@ -44,7 +44,9 @@ class EnableReassignClass(bpy.types.Operator):
def execute(self, context): def execute(self, context):
obj = context.active_object obj = context.active_object
self.file = tool.Ifc.get() self.file = tool.Ifc.get()
ifc_class = obj.name.split("/")[0] element = tool.Ifc.get_entity(obj)
assert element
ifc_class = element.is_a()
context.active_object.BIMObjectProperties.is_reassigning_class = True context.active_object.BIMObjectProperties.is_reassigning_class = True
ifc_products = [ ifc_products = [
"IfcElement", "IfcElement",
@@ -58,9 +60,16 @@ class EnableReassignClass(bpy.types.Operator):
"IfcRelSpaceBoundary", "IfcRelSpaceBoundary",
] ]
schema = tool.Ifc.schema() schema = tool.Ifc.schema()
declaration = schema.declaration_by_name(ifc_class)
for ifc_product in ifc_products: for ifc_product in ifc_products:
if schema.declaration_by_name(ifc_class).is_a(ifc_product): if ifcopenshell.util.schema.is_a(declaration, ifc_product):
context.scene.BIMRootProperties.ifc_product = ifc_product context.scene.BIMRootProperties.ifc_product = ifc_product
break
else:
self.report({"ERROR"}, f"Couldn't find matching IFC product for the selected object: '{element}'.")
obj.BIMObjectProperties.is_reassigning_class = False
return {"CANCELLED"}
element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id) element = self.file.by_id(obj.BIMObjectProperties.ifc_definition_id)
context.scene.BIMRootProperties.ifc_class = element.is_a() context.scene.BIMRootProperties.ifc_class = element.is_a()
context.scene.BIMRootProperties.relating_class_object = None context.scene.BIMRootProperties.relating_class_object = None