Fix bug in convert length unit recipe where IFC2X3 ownership history fails.

This commit is contained in:
Dion Moult
2021-11-19 19:12:55 +11:00
parent ebf6b9fc88
commit ff3a98234d
@@ -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