New IFCPatch recipe to optimise IFCs by recycling non rooted elements

This commit is contained in:
Dion Moult
2020-08-04 21:11:37 +10:00
parent 6772886e65
commit 61f6ecbf17
@@ -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