From 07f19ad80af5165e6dc7a23b6b2008f40f2640b2 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sun, 25 Jul 2021 12:00:05 +1000 Subject: [PATCH] New patch to fix duplicate Revit types. See commit message for details. Types in Revit are secretly duplicated (or more) if they are mirrored or hosted in another object unbeknownst to the user. So what the user thinks is a single construction type in Revit ends up being multiple IFC types. This leads to incorrect results when someone interrogates the IFC file. This is fundamentally an issue in the way Revit handles element mirroring and hosting, so there is no fix on the Revit side, so this workaround mitigates the issue by doing a shallow merge of the type objects. --- .../recipes/MergeDuplicateRevitTypes.py | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 src/ifcpatch/ifcpatch/recipes/MergeDuplicateRevitTypes.py diff --git a/src/ifcpatch/ifcpatch/recipes/MergeDuplicateRevitTypes.py b/src/ifcpatch/ifcpatch/recipes/MergeDuplicateRevitTypes.py new file mode 100644 index 0000000000..f1381411d5 --- /dev/null +++ b/src/ifcpatch/ifcpatch/recipes/MergeDuplicateRevitTypes.py @@ -0,0 +1,21 @@ +import ifcopenshell +import ifcopenshell.util.element + + +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): + tags = {} + for element in self.file.by_type("IfcTypeObject"): + original_element = tags.get(element.Tag, None) + if original_element: + for inverse in self.file.get_inverse(element): + ifcopenshell.util.element.replace_attribute(inverse, element, original_element) + self.file.remove(element) + else: + tags[element.Tag] = element