mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-19 22:50:21 +00:00
Fix reassign_class on IFC4X3, use ValueError
Use ValueError to make it more specific
This commit is contained in:
@@ -162,16 +162,20 @@ def reassign_class(
|
|||||||
(such as IfcRelNests)
|
(such as IfcRelNests)
|
||||||
|
|
||||||
It's unlikely that this affects real-world usage of this function.
|
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:
|
if not ifc_file:
|
||||||
ifc_file = element.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:
|
try:
|
||||||
declaration = schema.declaration_by_name(new_class)
|
declaration = schema.declaration_by_name(new_class)
|
||||||
except:
|
except RuntimeError:
|
||||||
raise Exception(f"Class of {element} could not be changed to {new_class} as the class does not exist")
|
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()
|
info = element.get_info()
|
||||||
|
|
||||||
|
|||||||
@@ -197,6 +197,10 @@ class TestReassignClass(test.bootstrap.IFC4):
|
|||||||
assert len(self.file.by_type("IfcSlab")) == 1
|
assert len(self.file.by_type("IfcSlab")) == 1
|
||||||
|
|
||||||
|
|
||||||
|
class TestReassignClassIFC4X3(test.bootstrap.IFC4X3, TestReassignClass):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestReassignClassIFC2X3(test.bootstrap.IFC2X3, TestReassignClass):
|
class TestReassignClassIFC2X3(test.bootstrap.IFC2X3, TestReassignClass):
|
||||||
def test_providing_occurrence_class(self):
|
def test_providing_occurrence_class(self):
|
||||||
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
element_type = ifcopenshell.api.root.create_entity(self.file, ifc_class="IfcWallType")
|
||||||
|
|||||||
Reference in New Issue
Block a user