From 392b4585631442c9480c9619cc6957c69e60c212 Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Thu, 3 Oct 2024 10:41:37 +0500 Subject: [PATCH] ifcopenshell.util.element.replace_element --- src/ifcopenshell-python/ifcopenshell/util/element.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 6f7d28509f..670c8a9953 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -1349,6 +1349,11 @@ def get_referenced_elements(reference: ifcopenshell.entity_instance) -> set[ifco return related_objects +def replace_element(element: ifcopenshell.entity_instance, replacement: ifcopenshell.entity_instance) -> None: + for inverse in element.file: + replace_attribute(inverse, element, replacement) + + def replace_attribute(element: ifcopenshell.entity_instance, old: Any, new: Any) -> None: for i, attribute_value in enumerate(element): if has_element_reference(attribute_value, old):