From ff3a98234d94a29eae69281fb05a66390b2c76d9 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 19 Nov 2021 19:12:55 +1100 Subject: [PATCH] Fix bug in convert length unit recipe where IFC2X3 ownership history fails. --- src/ifcpatch/ifcpatch/recipes/ConvertLengthUnit.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/ifcpatch/ifcpatch/recipes/ConvertLengthUnit.py b/src/ifcpatch/ifcpatch/recipes/ConvertLengthUnit.py index 96ef036b3c..11151fdd22 100644 --- a/src/ifcpatch/ifcpatch/recipes/ConvertLengthUnit.py +++ b/src/ifcpatch/ifcpatch/recipes/ConvertLengthUnit.py @@ -19,6 +19,7 @@ import ifcopenshell import ifcopenshell.api +import ifcopenshell.api.owner.settings import ifcopenshell.util.pset import ifcopenshell.util.element @@ -33,6 +34,10 @@ class Patcher: def patch(self): unit = {"is_metric": "METERS" in self.args[0], "raw": self.args[0]} self.file_patched = ifcopenshell.api.run("project.create_file", version=self.file.schema) + if self.file.schema == "IFC2X3": + user = self.file_patched.add(self.file.by_type("IfcProject")[0].OwnerHistory.OwningUser) + old_get_user = ifcopenshell.api.owner.settings.get_user + ifcopenshell.api.owner.settings.get_user = lambda ifc : user project = ifcopenshell.api.run("root.create_entity", self.file_patched, ifc_class="IfcProject") unit_assignment = ifcopenshell.api.run("unit.assign_unit", self.file_patched, **{"length": unit}) @@ -57,3 +62,6 @@ class Patcher: self.file_patched.remove(old_length) self.file_patched.remove(project) + + if self.file.schema == "IFC2X3": + ifcopenshell.api.owner.settings.get_user = old_get_user