From 2c79f07abf2f35e998bac812114658c3248bc2d8 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Sat, 15 Aug 2020 18:37:03 +1000 Subject: [PATCH] New purge classifications feature, and imported systems shows up immediately --- .../blenderbim/bim/__init__.py | 1 + .../blenderbim/bim/import_ifc.py | 7 ++++++- .../blenderbim/bim/operator.py | 19 +++++++++++++++++-- src/ifcblenderexport/blenderbim/bim/prop.py | 2 ++ src/ifcblenderexport/blenderbim/bim/schema.py | 2 ++ src/ifcblenderexport/blenderbim/bim/ui.py | 1 + 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index aa6737f885..32bf516e07 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -184,6 +184,7 @@ if bpy is not None: operator.SaveDrawingStyle, operator.ActivateDrawingStyle, operator.EditVectorStyle, + operator.PurgeProjectClassifications, prop.StrProperty, prop.Variable, prop.Role, diff --git a/src/ifcblenderexport/blenderbim/bim/import_ifc.py b/src/ifcblenderexport/blenderbim/bim/import_ifc.py index 15c7449981..3c328c04b6 100644 --- a/src/ifcblenderexport/blenderbim/bim/import_ifc.py +++ b/src/ifcblenderexport/blenderbim/bim/import_ifc.py @@ -1431,11 +1431,16 @@ class IfcImporter(): classification_filename = '{}-{}'.format( Path(os.path.basename(self.ifc_import_settings.input_file)).stem, element.Name) classification_file.write(os.path.join( - bpy.context.scene.BIMProperties.schema_dir, 'classifications', + bpy.context.scene.BIMProperties.schema_dir, 'project_classifications', '{}.ifc'.format(classification_filename))) classification.filename = classification_filename self.classifications[classification.filename] = classification + self.schema_dir = bpy.context.scene.BIMProperties.schema_dir + from . import prop + prop.classification_enum.clear() + prop.getClassifications(self, bpy.context) + def get_classification_references(self, references): results = [] for reference in references: diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 9f288ffce1..229c388a7e 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -1871,7 +1871,7 @@ class AddClassification(bpy.types.Operator): 'reference_tokens': 'ReferenceTokens' } for key, value in data_map.items(): - if getattr(data, value): + if hasattr(data, value) and getattr(data, value): setattr(classification, key, str(getattr(data, value))) classification.filename = context.scene.BIMProperties.classification return {'FINISHED'} @@ -3572,10 +3572,25 @@ class RemoveDrawing(bpy.types.Operator): class EditVectorStyle(bpy.types.Operator): bl_idname = 'bim.edit_vector_style' bl_label = 'Edit Vector Style' - index: bpy.props.IntProperty() def execute(self, context): camera = context.scene.camera vector_style = context.scene.DocProperties.drawing_styles[camera.data.BIMCameraProperties.active_drawing_style_index].vector_style bpy.data.texts.load(os.path.join(context.scene.BIMProperties.data_dir, 'styles', vector_style + '.css')) return {'FINISHED'} + + +class PurgeProjectClassifications(bpy.types.Operator): + bl_idname = 'bim.purge_project_classifications' + bl_label = 'Purge Project Classifications' + + def execute(self, context): + self.schema_dir = bpy.context.scene.BIMProperties.schema_dir + path = os.path.join(self.schema_dir, 'project_classifications') + files = os.listdir(path) + for f in files: + os.remove(os.path.join(path, f)) + from . import prop + prop.classification_enum.clear() + prop.getClassifications(self, context) + return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index 55d229996f..9d848fb063 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -304,6 +304,8 @@ def getClassifications(self, context): classification_enum.clear() files = os.listdir(os.path.join(self.schema_dir, 'classifications')) classification_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files]) + files = os.listdir(os.path.join(self.schema_dir, 'project_classifications')) + classification_enum.extend([(f.replace('.ifc', ''), f.replace('.ifc', ''), '') for f in files]) return classification_enum diff --git a/src/ifcblenderexport/blenderbim/bim/schema.py b/src/ifcblenderexport/blenderbim/bim/schema.py index 4298b81042..3b587ffff5 100644 --- a/src/ifcblenderexport/blenderbim/bim/schema.py +++ b/src/ifcblenderexport/blenderbim/bim/schema.py @@ -65,6 +65,8 @@ class IfcSchema(): def load_classification(self, filename): if filename not in self.classifications: classification_path = os.path.join(self.schema_dir, 'classifications', '{}.ifc'.format(filename)) + if not os.path.isfile(classification_path): + classification_path = os.path.join(self.schema_dir, 'project_classifications', '{}.ifc'.format(filename)) self.classification_files[filename] = ifcopenshell.open(classification_path) self.classifications[filename] = self.classification_files[filename].by_type('IfcClassification')[0] classification = self.classifications[filename] diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index 1497f23507..aed2076a86 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -512,6 +512,7 @@ class BIM_PT_classifications(Panel): row = layout.row(align=True) row.prop(props, "classification", text='') + row.operator("bim.purge_project_classifications", text='', icon='TRASH') row.operator("bim.add_classification", text='', icon='ADD') if context.scene.BIMProperties.classification_references.raw_data: