From 6772886e65064e16da2e46475811c7b91479ade9 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 4 Aug 2020 21:08:49 +1000 Subject: [PATCH] New utility function to replace an attribute --- src/ifcopenshell-python/ifcopenshell/util/element.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/ifcopenshell-python/ifcopenshell/util/element.py b/src/ifcopenshell-python/ifcopenshell/util/element.py index 44f8e1b2f4..19cd633a71 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/element.py +++ b/src/ifcopenshell-python/ifcopenshell/util/element.py @@ -51,3 +51,15 @@ def get_properties(properties): del(data['HasProperties']) results[prop.Name] = data return results + + +def replace_attribute(element, old, new): + for i, attribute in enumerate(element): + if attribute == old: + element[i] = new + elif isinstance(attribute, tuple): + new_attribute = list(attribute) + for j, item in enumerate(attribute): + if item == old: + new_attribute[j] = new + element[i] = new_attribute