diff --git a/src/ifcblenderexport/blenderbim/bim/export_ifc.py b/src/ifcblenderexport/blenderbim/bim/export_ifc.py index 00b33ab874..674668801d 100644 --- a/src/ifcblenderexport/blenderbim/bim/export_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/export_ifc.py @@ -140,6 +140,7 @@ class IfcParser(): self.document_information = self.get_document_information() self.document_references = self.get_document_references() self.classifications = self.get_classifications() + self.classification_reference_maps = self.get_classification_reference_maps() self.classification_references = self.get_classification_references() self.objectives = self.get_objectives() self.load_representations() @@ -615,25 +616,22 @@ class IfcParser(): return results def get_classifications(self): - classifications = bpy.context.scene.BIMProperties.classifications results = {} - for classification in classifications: - results[classification.name] = { + for classification in bpy.context.scene.BIMProperties.classifications: + schema.ifc.load_classification(classification.filename) + results[classification.filename] = { 'ifc': None, 'raw': classification, - 'attributes': { - 'Name': classification.name, - 'Source': classification.source, - 'Edition': classification.edition, - 'EditionDate': classification.edition_date, - 'Description': classification.description, - 'Location': classification.location, - 'ReferenceTokens': json.loads( - '[{}]'.format(classification.reference_tokens[1:-1].replace('\'', '"').strip(','))) - } + 'raw_element': schema.ifc.classification_files[classification.filename].by_type('IfcClassification')[0] } return results + def get_classification_reference_maps(self): + results = {} + for filename, classification in self.classifications.items(): + results[filename] = { e.Identification: e for e in schema.ifc.classification_files[filename].by_type('IfcClassificationReference')} + return results + def get_classification_references(self): results = {} for product in self.selected_products: @@ -641,13 +639,8 @@ class IfcParser(): results[reference.name] = { 'ifc': None, 'raw': reference, - 'referenced_source': reference.referenced_source, - 'attributes': { - 'Location': reference.location, - 'Identification': reference.name, - 'Name': reference.human_name, - 'Description': reference.description - } + 'raw_element': self.classification_reference_maps[reference.referenced_source][reference.name] + } return results @@ -1359,20 +1352,14 @@ class IfcExporter(): def create_classifications(self): for classification in self.ifc_parser.classifications.values(): - classification['ifc'] = self.file.create_entity( - 'IfcClassification', - **classification['attributes'] - ) + classification['ifc'] = self.file.add(classification['raw_element']) self.file.createIfcRelAssociatesClassification( ifcopenshell.guid.new(), None, None, None, [self.ifc_parser.project['ifc']], classification['ifc']) def create_classification_references(self): for reference in self.ifc_parser.classification_references.values(): - reference['attributes']['ReferencedSource'] = \ - self.ifc_parser.classifications[reference['referenced_source']]['ifc'] - reference['ifc'] = self.file.create_entity( - 'IfcClassificationReference', **reference['attributes']) + reference['ifc'] = self.file.add(reference['raw_element']) def create_objectives(self): for objective in self.ifc_parser.objectives.values(): diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index 73d630bfa9..0889546204 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -741,9 +741,7 @@ class IfcImporter(): Path(os.path.basename(self.ifc_import_settings.input_file)).stem, classification.Name) classification_file.write(os.path.join( bpy.context.scene.BIMProperties.schema_dir, 'classifications', classification_filename)) - - destination = os.path.join(bpy.context.scene.BIMProperties.schema_dir, - 'classifications', '{}-{}.ifc') + data.filename = classification_filename def get_classification_references(self, references): results = [] @@ -970,7 +968,7 @@ class IfcImporter(): for key, value in data_map.items(): if hasattr(data, value) and getattr(data, value): setattr(reference, key, getattr(data, value)) - if data.ReferencedSource: + if hasattr(data, 'ReferencedSource') and data.ReferencedSource: reference.referenced_source = self.get_referenced_source_name(data.ReferencedSource) def get_referenced_source_name(self, element): diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 465088bc19..4a03abafc5 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1342,18 +1342,20 @@ class AddClassification(bpy.types.Operator): bl_label = 'Add Classification' def execute(self, context): - if context.scene.BIMProperties.classification in schema.ifc.classifications: - data = schema.ifc.classifications[context.scene.BIMProperties.classification] - classification = context.scene.BIMProperties.classifications.add() - data_map = { - 'name': 'Name', 'source': 'Source', - 'edition': 'Edition', 'edition_date': 'EditionDate', - 'description': 'Description', 'location': 'Location', - 'reference_tokens': 'ReferenceTokens' - } - for key, value in data_map.items(): - if getattr(data, value): - setattr(classification, key, str(getattr(data, value))) + if context.scene.BIMProperties.classification not in schema.ifc.classifications: + return {'FINISHED'} + data = schema.ifc.classifications[context.scene.BIMProperties.classification] + classification = context.scene.BIMProperties.classifications.add() + data_map = { + 'name': 'Name', 'source': 'Source', + 'edition': 'Edition', 'edition_date': 'EditionDate', + 'description': 'Description', 'location': 'Location', + 'reference_tokens': 'ReferenceTokens' + } + for key, value in data_map.items(): + if getattr(data, value): + setattr(classification, key, str(getattr(data, value))) + classification.filename = context.scene.BIMProperties.classification return {'FINISHED'} @@ -1372,7 +1374,6 @@ class AssignClassification(bpy.types.Operator): bl_label = 'Assign Classification' def execute(self, context): - referenced_source = schema.ifc.classifications[bpy.context.scene.BIMProperties.classification].Name for obj in bpy.context.selected_objects: classification = obj.BIMObjectProperties.classifications.add() refs = bpy.context.scene.BIMProperties.classification_references @@ -1384,7 +1385,7 @@ class AssignClassification(bpy.types.Operator): for key in ['location', 'description']: if data[key]: setattr(classification, key, data[key]) - classification.referenced_source = referenced_source + classification.referenced_source = bpy.context.scene.BIMProperties.classification return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 1ec0137a4e..4ce1fce0d9 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -753,6 +753,7 @@ class Classification(PropertyGroup): description: StringProperty(name="Description") location: StringProperty(name="Location") reference_tokens: StringProperty(name="Reference Tokens") + filename: StringProperty(name="Filename") class ClassificationReference(PropertyGroup): diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 7347894c63..db26fd4908 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -231,6 +231,7 @@ class BIM_PT_classification_references(Panel): def draw(self, context): layout = self.layout + layout.use_property_split = True props = context.active_object.BIMObjectProperties if not props.classifications: