element.get_type - check schema explicitly for a small optimization

Previously if product had no types it would still run through all element.IsDefinedBy and check if they are IfcRelDefinesByType even if it's not IFC2X3.
This commit is contained in:
Andrej730
2024-06-21 15:16:34 +05:00
parent 68d3539a86
commit d443c5e2a6
@@ -463,9 +463,14 @@ def get_type(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity
"""
if element.is_a("IfcTypeObject"):
return element
elif (is_typed_by := getattr(element, "IsTypedBy", None)) is not None and is_typed_by:
return is_typed_by[0].RelatingType
elif (is_defined_by := getattr(element, "IsDefinedBy", None)) is not None and is_defined_by: # IFC2X3
schema = element.file.schema
if schema != "IFC2X3":
if is_typed_by := element.IsTypedBy:
return is_typed_by[0].RelatingType
return
if is_defined_by := element.IsDefinedBy: # IFC2X3
for relationship in is_defined_by:
if relationship.is_a("IfcRelDefinesByType"):
return relationship.RelatingType