From d443c5e2a63c1caae9cb62811365f9749a6fd360 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Fri, 21 Jun 2024 15:16:34 +0500 Subject: [PATCH] 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. --- src/ifcopenshell-python/ifcopenshell/util/element.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 3932f4fd95..728050e7f4 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -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