From bdc8caa5f684add291e562f16dd510b65982c90d Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Fri, 21 Feb 2020 09:41:35 +1100 Subject: [PATCH] New feature to colour code objects by attribute or pset values --- src/ifcblenderexport/blenderbim/__init__.py | 2 + src/ifcblenderexport/blenderbim/operator.py | 82 ++++++++++++++++----- src/ifcblenderexport/blenderbim/prop.py | 3 +- src/ifcblenderexport/blenderbim/ui.py | 5 +- 4 files changed, 71 insertions(+), 21 deletions(-) diff --git a/src/ifcblenderexport/blenderbim/__init__.py b/src/ifcblenderexport/blenderbim/__init__.py index 5a018c3a27..2d101989fb 100644 --- a/src/ifcblenderexport/blenderbim/__init__.py +++ b/src/ifcblenderexport/blenderbim/__init__.py @@ -44,6 +44,8 @@ if bpy is not None: operator.ExportIFC, operator.ImportIFC, operator.ColourByClass, + operator.ColourByAttribute, + operator.ColourByPset, operator.ResetObjectColours, operator.ApproveClass, operator.RejectClass, diff --git a/src/ifcblenderexport/blenderbim/operator.py b/src/ifcblenderexport/blenderbim/operator.py index 11ef247baf..23c5f88325 100644 --- a/src/ifcblenderexport/blenderbim/operator.py +++ b/src/ifcblenderexport/blenderbim/operator.py @@ -14,6 +14,20 @@ from itertools import cycle from mathutils import Vector from pathlib import Path +colour_list = [ + (.651, .81, .892, 1), + (.121, .471, .706, 1), + (.699, .876, .54, 1), + (.199, .629, .174, 1), + (.983, .605, .602, 1), + (.89, .101, .112, 1), + (.989, .751, .427, 1), + (.986, .497, .1, 1), + (.792, .699, .839, 1), + (.414, .239, .603, 1), + (.993, .999, .6, 1), + (.693, .349, .157, 1)] + class ExportIFC(bpy.types.Operator): bl_idname = "export.ifc" bl_label = "Export .ifc file" @@ -137,8 +151,8 @@ class SelectPset(bpy.types.Operator): def execute(self, context): import re - search_pset_name = bpy.context.scene.BIMProperties.search_pset_path.split('.')[0] - search_prop_name = bpy.context.scene.BIMProperties.search_pset_path.split('.')[1] + search_pset_name = bpy.context.scene.BIMProperties.search_pset_name + search_prop_name = bpy.context.scene.BIMProperties.search_prop_name search_value = bpy.context.scene.BIMProperties.search_pset_value for object in bpy.context.visible_objects: pset_index = object.BIMObjectProperties.override_psets.find(search_pset_name) @@ -232,30 +246,60 @@ class ColourByClass(bpy.types.Operator): bl_label = 'Colour by Class' def execute(self, context): - colour_list = [ - (.651, .81, .892, 1), - (.121, .471, .706, 1), - (.699, .876, .54, 1), - (.199, .629, .174, 1), - (.983, .605, .602, 1), - (.89, .101, .112, 1), - (.989, .751, .427, 1), - (.986, .497, .1, 1), - (.792, .699, .839, 1), - (.414, .239, .603, 1), - (.993, .999, .6, 1), - (.693, .349, .157, 1)] colours = cycle(colour_list) ifc_classes = {} - for object in bpy.context.selected_objects: - if '/' not in object.name: + for obj in bpy.context.visible_objects: + if '/' not in obj.name: continue - ifc_class = object.name.split('/')[0] + ifc_class = obj.name.split('/')[0] if ifc_class not in ifc_classes: ifc_classes[ifc_class] = next(colours) - object.color = ifc_classes[ifc_class] + obj.color = ifc_classes[ifc_class] return {'FINISHED'} + +class ColourByAttribute(bpy.types.Operator): + bl_idname = 'bim.colour_by_attribute' + bl_label = 'Colour by Attribute' + + def execute(self, context): + colours = cycle(colour_list) + values = {} + attribute_name = bpy.context.scene.BIMProperties.search_attribute_name + for obj in bpy.context.visible_objects: + index = obj.BIMObjectProperties.attributes.find(attribute_name) + if index == -1: + continue + value = obj.BIMObjectProperties.attributes[index].string_value + if value not in values: + values[value] = next(colours) + obj.color = values[value] + return {'FINISHED'} + + +class ColourByPset(bpy.types.Operator): + bl_idname = 'bim.colour_by_pset' + bl_label = 'Colour by Pset' + + def execute(self, context): + colours = cycle(colour_list) + values = {} + search_pset_name = bpy.context.scene.BIMProperties.search_pset_name + search_prop_name = bpy.context.scene.BIMProperties.search_prop_name + for obj in bpy.context.visible_objects: + pset_index = obj.BIMObjectProperties.override_psets.find(search_pset_name) + if pset_index == -1: + continue + prop_index = obj.BIMObjectProperties.override_psets[pset_index].properties.find(search_prop_name) + if prop_index == -1: + continue + value = obj.BIMObjectProperties.override_psets[pset_index].properties[prop_index].string_value + if value not in values: + values[value] = next(colours) + obj.color = values[value] + return {'FINISHED'} + + class ResetObjectColours(bpy.types.Operator): bl_idname = 'bim.reset_object_colours' bl_label = 'Reset Colours' diff --git a/src/ifcblenderexport/blenderbim/prop.py b/src/ifcblenderexport/blenderbim/prop.py index c05a981604..c8b2f773c6 100644 --- a/src/ifcblenderexport/blenderbim/prop.py +++ b/src/ifcblenderexport/blenderbim/prop.py @@ -393,7 +393,8 @@ class BIMProperties(PropertyGroup): global_id: StringProperty(name="GlobalId") search_attribute_name: StringProperty(name="Search Attribute Name") search_attribute_value: StringProperty(name="Search Attribute Value") - search_pset_path: StringProperty(name="Search Pset Path") + search_pset_name: StringProperty(name="Search Pset Name") + search_prop_name: StringProperty(name="Search Prop Name") search_pset_value: StringProperty(name="Search Pset Value") features_dir: StringProperty(default='', name="Features Directory", update=refreshFeaturesFiles) features_file: EnumProperty(items=getFeaturesFiles, name="Features File", update=refreshScenarios) diff --git a/src/ifcblenderexport/blenderbim/ui.py b/src/ifcblenderexport/blenderbim/ui.py index be6eed92fe..afa185de1d 100644 --- a/src/ifcblenderexport/blenderbim/ui.py +++ b/src/ifcblenderexport/blenderbim/ui.py @@ -494,12 +494,15 @@ class BIM_PT_search(Panel): row.prop(props, 'search_attribute_name', text='') row.prop(props, 'search_attribute_value', text='') row.operator('bim.select_attribute', text='', icon='VIEWZOOM') + row.operator('bim.colour_by_attribute', text='', icon='BRUSH_DATA') layout.label(text="Pset:") row = layout.row(align=True) - row.prop(props, 'search_pset_path', text='') + row.prop(props, 'search_pset_name', text='') + row.prop(props, 'search_prop_name', text='') row.prop(props, 'search_pset_value', text='') row.operator('bim.select_pset', text='', icon='VIEWZOOM') + row.operator('bim.colour_by_pset', text='', icon='BRUSH_DATA') class BIM_PT_qa(Panel):