From b2c5153c1c31eb7ceacc2f54cc414f060474dc4f Mon Sep 17 00:00:00 2001 From: Boris Brangeon Date: Wed, 19 Oct 2022 09:48:55 +0200 Subject: [PATCH] Add IsGroupedBy in function get_decomposition (#2513) * Add IsGroupedBy in function get_decomposition selector example : "@ .IfcZone & .IfcSpace" * Update element.py * Change name function get_group get_group to get_grouped_by --- .../ifcopenshell/util/element.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 239c4ceee2..8f3ecbabf6 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -376,7 +376,27 @@ def get_decomposition(element): results.append(rel.RelatedBuildingElement) return results +def get_grouped_by(element): + """ + Retrieves all subelements of an element based on the group. + :param element: The IFC element + :return: All subelements of the group + + Example:: + + element = file.by_type("IfcGroup")[0] + subelements = ifcopenshell.util.element.get_group(element) + """ + queue = [element] + results = [] + while queue: + element = queue.pop() + for rel in getattr(element, "IsGroupedBy", []): + queue.extend(rel.RelatedObjects) + results.extend(rel.RelatedObjects) + return results + def get_aggregate(element): """ Retrieves the aggregate of an element.