From b91b1401f41518b8efa95e7bc392f8cc891543a9 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 13 May 2025 17:42:41 +0500 Subject: [PATCH] util.get_aggregate - make it more readable (5597095) --- .../ifcopenshell/util/element.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 0643d7480a..371e5b8661 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1255,10 +1255,15 @@ def get_aggregate(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.e element = file.by_type("IfcBeam")[0] aggregate = ifcopenshell.util.element.get_aggregate(element) """ - if decomposes := getattr(element, "Decomposes", None): - is_not_ifc2x3 = element.file.schema != "IFC2X3" - if is_not_ifc2x3 or decomposes[0].is_a("IfcRelAggregates"): - return decomposes[0].RelatingObject + if not (decomposes := getattr(element, "Decomposes", None)): + return + is_ifc2x3 = element.file.schema == "IFC2X3" + rel: ifcopenshell.entity_instance = decomposes[0] + if is_ifc2x3 and not rel.is_a("IfcRelAggregates"): + # In IFCF2X3 Decomposes is used for both aggregates and nests, + # but only for 1 at the time. + return + return rel.RelatingObject def get_nest(element: ifcopenshell.entity_instance) -> Union[ifcopenshell.entity_instance, None]: