From 3ee6bdf207d974d2ee586f53c4225a6fc45fb4c3 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Mon, 5 Jun 2023 15:11:55 +1000 Subject: [PATCH] You can now get decompositions non-recursively in element utilities --- src/ifcopenshell-python/ifcopenshell/util/element.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index bbe170bc6c..6e9e0a3bc9 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -609,14 +609,16 @@ def get_referenced_structures(element): return [] -def get_decomposition(element): +def get_decomposition(element, is_recursive=True): """ Retrieves all subelements of an element based on the spatial decomposition hierarchy. This includes all subspaces and elements contained in subspaces, parts of an aggreate, all openings, and all fills of any openings. :param element: The IFC element + :type element: ifcopenshell.entity_instance.entity_instance :return: The decomposition of the element + :rtype: list[ifcopenshell.entity_instance.entity_instance] Example: @@ -644,6 +646,8 @@ def get_decomposition(element): for rel in getattr(element, "IsNestedBy", []): queue.extend(rel.RelatedObjects) results.extend(rel.RelatedObjects) + if not is_recursive: + break return results @@ -682,7 +686,6 @@ def get_aggregate(element): .. code:: python element = file.by_type("IfcBeam")[0] aggregate = ifcopenshell.util.element.get_aggregate(element) - """ if hasattr(element, "Decomposes") and element.Decomposes: return element.Decomposes[0].RelatingObject