From 395d5ebea72147bd9849ea870f674555d56358ea Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Thu, 14 May 2020 21:35:43 +1000 Subject: [PATCH] Fix round-trip bug when IFC2X3 classifications are imported. See #851. --- .../blenderbim/bim/import_ifc.py | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index d4f75bbfbb..75156f90ed 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -836,14 +836,23 @@ class IfcImporter(): for key, value in data_map.items(): if hasattr(element, value) and getattr(element, value): setattr(classification, key, str(getattr(element, value))) - classification_file = ifcopenshell.file(schema=self.file.wrapped_data.schema) - references = [element] - while references: - entities_to_add = references - references = self.get_classification_references(references) - classification_file.add(element) - for entity in entities_to_add: - classification_file.add(entity) + classification_file = ifcopenshell.file() + + # IFC2X3 has no references, so let's manually add them + if self.file.wrapped_data.schema == 'IFC2X3': + classification_element = classification_file.createIfcClassification( + element.Source, element.Edition, element.EditionDate, element.Name) + for reference in self.file.by_type('IfcClassificationReference'): + classification_file.createIfcClassificationReference( + reference.Location, reference.ItemReference, reference.Name, classification_element) + else: + references = [element] + while references: + entities_to_add = references + references = self.get_classification_references(references) + for entity in entities_to_add: + classification_file.add(entity) + classification_filename = '{}-{}'.format( Path(os.path.basename(self.ifc_import_settings.input_file)).stem, element.Name) classification_file.write(os.path.join( @@ -1094,6 +1103,8 @@ class IfcImporter(): 'name': 'Identification', 'location': 'Location', 'human_name': 'Name', 'description': 'Description', 'sort': 'Sort' } + if self.file.schema == 'IFC2X3': + data_map['name'] = 'ItemReference' for key, value in data_map.items(): if hasattr(data, value) and getattr(data, value): setattr(reference, key, getattr(data, value))