Fix reassign_class on IFC4X3, use ValueError

Use ValueError to make it more specific
This commit is contained in:
Andrej730
2025-03-12 16:48:51 +05:00
parent f6640d3904
commit dbf4a2a5ed
2 changed files with 11 additions and 3 deletions
@@ -162,16 +162,20 @@ def reassign_class(
(such as IfcRelNests)
It's unlikely that this affects real-world usage of this function.
:raises ValueError: If ``new_class`` does not exist in the provided file schema.
"""
if not ifc_file:
ifc_file = element.file
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(ifc_file.schema)
schema: ifcopenshell_wrapper.schema_definition = ifcopenshell_wrapper.schema_by_name(ifc_file.schema_identifier)
try:
declaration = schema.declaration_by_name(new_class)
except:
raise Exception(f"Class of {element} could not be changed to {new_class} as the class does not exist")
except RuntimeError:
raise ValueError(
f"Class of {element} could not be changed to {new_class} as the class does not exist in schema {ifc_file.schema_identifier}."
)
info = element.get_info()
@@ -197,6 +197,10 @@ class TestReassignClass(test.bootstrap.IFC4):
assert len(self.file.by_type("IfcSlab")) == 1
class TestReassignClassIFC4X3(test.bootstrap.IFC4X3, TestReassignClass):
pass
class TestReassignClassIFC2X3(test.bootstrap.IFC2X3, TestReassignClass):
def test_providing_occurrence_class(self):
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")