From 61f6ecbf179bae1eca6baef378c246a35100d414 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Tue, 4 Aug 2020 21:11:37 +1000 Subject: [PATCH] New IFCPatch recipe to optimise IFCs by recycling non rooted elements --- .../recipes/RecycleNonRootedElements.py | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 src/ifcpatch/recipes/RecycleNonRootedElements.py diff --git a/src/ifcpatch/recipes/RecycleNonRootedElements.py b/src/ifcpatch/recipes/RecycleNonRootedElements.py new file mode 100644 index 0000000000..6407e24150 --- /dev/null +++ b/src/ifcpatch/recipes/RecycleNonRootedElements.py @@ -0,0 +1,20 @@ +class Patcher: + def __init__(self, src, file, logger, args=None): + self.src = src + self.file = file + self.logger = logger + self.args = args + + def patch(self): + import ifcopenshell.util.element + hashes = {} + for element in self.file: + if element.is_a('IfcRoot'): + continue + h = hash(tuple(element)) + if h in hashes: + for inverse in f.get_inverse(element): + ifcopenshell.util.element.replace_attribute(inverse, element, hashes[h]) + self.file.remove(element) + else: + hashes[h] = element