Fixed issue reassigning class to type class with userdefined type #4018

When PredefinedType is not found in the related enum reassign_class is considering it USERDEFINED and trying to set .ObjectType. The problem was it was doing for type classes also, when it should have set .ElementType instead.

Why it crashed BlenderBIM - in IfcClassData.data["has_entity"] we store currently active IFC entity which is recreated during `ifcopenshell.util.schema.reassign_class` making old entity invalid. Since `root.reassign_class` was failing in the process, related BBIM operator was failing too, IfcClassData wasn't updated and removed entity was accessed from UI leading to crash.
This commit is contained in:
Andrej730
2023-11-21 12:34:53 +05:00
parent 1dd401d77e
commit 6fd629f707
2 changed files with 20 additions and 4 deletions
@@ -35,10 +35,18 @@ class TestReassignClass(test.bootstrap.IFC4):
)
assert new.PredefinedType == "FLOOR"
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned(self):
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_occurrence_class(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWall")
new = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element, ifc_class="IfcSlab", predefined_type="FOO"
)
assert new.PredefinedType == "USERDEFINED"
assert new.ObjectType == "FOO"
def test_falling_back_to_userdefined_if_the_predefined_type_cannot_be_reassigned_for_type_class(self):
element = ifcopenshell.api.run("root.create_entity", self.file, ifc_class="IfcWallType")
new = ifcopenshell.api.run(
"root.reassign_class", self.file, product=element, ifc_class="IfcSlabType", predefined_type="FOO"
)
assert new.PredefinedType == "USERDEFINED"
assert new.ElementType == "FOO"