From 900aa20e107fb4073fd7c2f50000ad207d13197c Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 24 Jan 2021 14:32:04 +1100 Subject: [PATCH] New "remove deep" function in the element util module. See #1228. --- src/ifcopenshell-python/ifcopenshell/util/element.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index ddab485dc1..f947dccfc0 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -118,6 +118,14 @@ def is_representation_of_context(representation, context, subcontext=None, targe return True +def remove_deep(ifc_file, element): + subgraph = list(ifc_file.traverse(element)) + subgraph_set = set(subgraph) + for ref in subgraph[::-1]: + if ref.id() and len(set(ifc_file.get_inverse(ref)) - subgraph_set) == 0: + ifc_file.remove(ref) + + def get_representation(element, context, subcontext=None, target_view=None): if element.is_a("IfcProduct") and element.Representation: for r in element.Representation.Representations: