diff --git a/src/ifcblenderexport/Makefile b/src/ifcblenderexport/Makefile index 7a00ca9ba7..a388a007f0 100644 --- a/src/ifcblenderexport/Makefile +++ b/src/ifcblenderexport/Makefile @@ -39,11 +39,13 @@ endif cd dist/blenderbim/libs/site/packages/ifcopenshell/util && rm -f selector.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && rm -f unit.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && rm -f pset.py + cd dist/blenderbim/libs/site/packages/ifcopenshell/util && rm -f schema.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/element.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/geolocation.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/selector.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/unit.py cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/pset.py + cd dist/blenderbim/libs/site/packages/ifcopenshell/util && wget https://raw.githubusercontent.com/IfcOpenShell/IfcOpenShell/v0.6.0/src/ifcopenshell-python/ifcopenshell/util/schema.py # Provides Python OCC functionality for cutting IFC geometry for construction documentation mkdir dist/working diff --git a/src/ifcblenderexport/blenderbim/bim/export_ifc.py b/src/ifcblenderexport/blenderbim/bim/export_ifc.py index b58e6df589..b371777790 100644 --- a/src/ifcblenderexport/blenderbim/bim/export_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/export_ifc.py @@ -9,6 +9,7 @@ import zipfile import tempfile import ifcopenshell import ifcopenshell.util.pset +import ifcopenshell.util.schema from pathlib import Path from mathutils import Vector, Matrix from .helper import SIUnitHelper @@ -2356,7 +2357,11 @@ class IfcExporter: print("Authoring an IFC definition directly is not yet implemented") return elif representation["ifc_definition_id"]: - entry = self.file.add(ifc.IfcStore.get_file().by_id(representation["ifc_definition_id"])) + if self.file.schema == ifc.IfcStore.get_file().schema: + entry = self.file.add(ifc.IfcStore.get_file().by_id(representation["ifc_definition_id"])) + else: + migrator = ifcopenshell.util.schema.Migrator() + entry = migrator.migrate(ifc.IfcStore.get_file().by_id(representation["ifc_definition_id"]), self.file) substitutions = {"contexts": []} @@ -2365,7 +2370,10 @@ class IfcExporter: ) for element in representation_elements: - added_element = self.file.add(element) + if self.file.schema == ifc.IfcStore.get_file().schema: + added_element = self.file.add(element) + else: + added_element = migrator.migrate(element, self.file) if added_element.is_a("IfcGeometricRepresentationContext"): substitutions["contexts"].append(added_element) diff --git a/src/ifcopenshell-python/ifcopenshell/util/schema.py b/src/ifcopenshell-python/ifcopenshell/util/schema.py index a86ab47937..d408f0dc17 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/schema.py +++ b/src/ifcopenshell-python/ifcopenshell/util/schema.py @@ -70,10 +70,10 @@ class Migrator: return new_file.by_id(self.migrated_ids[element.id()]) except: pass - print("Migrating", element) + #print("Migrating", element) schema = ifcopenshell.ifcopenshell_wrapper.schema_by_name(new_file.schema) new_element = self.migrate_class(element, new_file) - print("Migrated class from {} to {}".format(element, new_element)) + #print("Migrated class from {} to {}".format(element, new_element)) new_element_schema = schema.declaration_by_name(new_element.is_a()) if not hasattr(new_element_schema, "all_attributes"): return element # The element has no attributes, so migration is done @@ -91,6 +91,7 @@ class Migrator: new_element = new_file.create_entity(self.class_4_to_2x3[element.is_a()]) elif new_file.schema == "IFC4": print("Class migration to IFC4 not yet supported for", element) + pass return new_element def migrate_attributes(self, element, new_file, new_element, new_element_schema): @@ -101,18 +102,18 @@ class Migrator: return new_element def migrate_attribute(self, attribute, element, new_file, new_element, new_element_schema): - print("Migrating attribute", element, new_element, attribute.name()) + #print("Migrating attribute", element, new_element, attribute.name()) if hasattr(element, attribute.name()): value = getattr(element, attribute.name()) - print("Attribute names matched", value) + #print("Attribute names matched", value) elif new_file.schema == "IFC2X3": # IFC4 to IFC2X3: We know the IFC2X3 attribute name, but not its IFC4 equivalent - print("Searching for an equivalent", new_element, attribute.name()) + #print("Searching for an equivalent", new_element, attribute.name()) try: equivalent_map = self.attribute_4_to_2x3[new_element.is_a()] equivalent = list(equivalent_map.keys())[list(equivalent_map.values()).index(attribute.name())] if hasattr(element, equivalent): - print("Equivalent found", equivalent) + #print("Equivalent found", equivalent) value = getattr(element, equivalent) else: return @@ -121,10 +122,10 @@ class Migrator: return # We tried our best elif new_file.schema == "IFC4": # IFC2X3 to IFC4: We know the IFC4 attribute name, but not its IFC2X3 equivalent - print("Searching for an equivalent", element, new_element, attribute.name()) + #print("Searching for an equivalent", element, new_element, attribute.name()) try: equivalent = self.attribute_4_to_2x3[new_element.is_a()][attribute.name()] - print("Searching for equivalent", equivalent) + #print("Searching for equivalent", equivalent) if hasattr(element, equivalent): value = getattr(element, equivalent) else: @@ -133,7 +134,7 @@ class Migrator: print("Unable to find equivalent attribute of {} to migrate from {} to {}".format(attribute.name(), element, new_element)) return # We tried our best - print("Continuing migration of {} to migrate from {} to {}".format(attribute.name(), element, new_element)) + #print("Continuing migration of {} to migrate from {} to {}".format(attribute.name(), element, new_element)) if value is None and not attribute.optional(): value = self.generate_default_value(attribute, new_file) if value is None: