From 884e8a5663efc91a63446c8388a50c21d2768459 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 4 Dec 2020 11:52:18 +1100 Subject: [PATCH] Fix #1071. New IFC file version 2X3<->4 upgrader and downgrader IfcPatch recipe --- src/ifcblenderexport/Makefile | 1 + .../ifcopenshell/util/schema.py | 9 --------- src/ifcpatch/recipes/Migrate.py | 18 ++++++++++++++++++ 3 files changed, 19 insertions(+), 9 deletions(-) create mode 100644 src/ifcpatch/recipes/Migrate.py diff --git a/src/ifcblenderexport/Makefile b/src/ifcblenderexport/Makefile index 5690f7a628..17ade9b9e8 100644 --- a/src/ifcblenderexport/Makefile +++ b/src/ifcblenderexport/Makefile @@ -296,6 +296,7 @@ endif cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/__init__.py cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/ExtractElements.py cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/MergeProject.py + cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/Migrate.py cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/OffsetObjectPlacements.py cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/OffsetStoreyElevations.py cd dist/blenderbim/libs/site/packages/recipes && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcpatch/recipes/Optimise.py diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index acffe3967f..ca10e72246 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -201,12 +201,3 @@ class Migrator: } ) return self.default_entities[attribute.name()] - - -# f = ifcopenshell.open("/home/dion/migrate.ifc") -# g = ifcopenshell.file(schema="IFC4") -# migrator = Migrator() -# for e in f: -# print(e) -# print(migrator.migrate(e, g)) -# g.write("/home/dion/migrate2.ifc") diff --git a/src/ifcpatch/recipes/Migrate.py b/src/ifcpatch/recipes/Migrate.py new file mode 100644 index 0000000000..610cb4934d --- /dev/null +++ b/src/ifcpatch/recipes/Migrate.py @@ -0,0 +1,18 @@ +import ifcopenshell +import ifcopenshell.util.schema + + +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): + self.new = ifcopenshell.file(schema=self.args[0]) + migrator = ifcopenshell.util.schema.Migrator() + for element in self.file: + print("Migrating", element) + print("Successfully converted to", migrator.migrate(element, self.new)) + self.file = self.new