From 01d0d125a63eb8aa712e4e8443f2966cdfe4a023 Mon Sep 17 00:00:00 2001 From: Dion Moult Date: Wed, 12 Aug 2020 19:59:30 +1000 Subject: [PATCH] Utility to quickly set object colours, also colour mode is automatically changed now --- .../blenderbim/bim/__init__.py | 2 ++ .../blenderbim/bim/operator.py | 21 +++++++++++++++++++ src/ifcblenderexport/blenderbim/bim/prop.py | 1 + src/ifcblenderexport/blenderbim/bim/ui.py | 17 +++++++++++++++ 4 files changed, 41 insertions(+) diff --git a/src/ifcblenderexport/blenderbim/bim/__init__.py b/src/ifcblenderexport/blenderbim/bim/__init__.py index 429a4de4a6..2aef58685a 100644 --- a/src/ifcblenderexport/blenderbim/bim/__init__.py +++ b/src/ifcblenderexport/blenderbim/bim/__init__.py @@ -179,6 +179,7 @@ if bpy is not None: operator.CalculateFaceAreas, operator.CalculateObjectVolumes, operator.AddOpening, + operator.SetOverrideColour, prop.StrProperty, prop.Variable, prop.Role, @@ -255,6 +256,7 @@ if bpy is not None: ui.BIM_PT_text, ui.BIM_PT_modeling_utilities, ui.BIM_PT_qto_utilities, + ui.BIM_PT_misc_utilities, ui.BIM_UL_generic, ui.BIM_UL_clash_sets, ui.BIM_UL_constraints, diff --git a/src/ifcblenderexport/blenderbim/bim/operator.py b/src/ifcblenderexport/blenderbim/bim/operator.py index 81bce4a736..93dc554e4b 100644 --- a/src/ifcblenderexport/blenderbim/bim/operator.py +++ b/src/ifcblenderexport/blenderbim/bim/operator.py @@ -268,6 +268,8 @@ class ColourByClass(bpy.types.Operator): if ifc_class not in ifc_classes: ifc_classes[ifc_class] = next(colours) obj.color = ifc_classes[ifc_class] + area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') + area.spaces[0].shading.color_type = 'OBJECT' return {'FINISHED'} @@ -287,6 +289,8 @@ class ColourByAttribute(bpy.types.Operator): if value not in values: values[value] = next(colours) obj.color = values[value] + area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') + area.spaces[0].shading.color_type = 'OBJECT' return {'FINISHED'} @@ -310,6 +314,8 @@ class ColourByPset(bpy.types.Operator): if value not in values: values[value] = next(colours) obj.color = values[value] + area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') + area.spaces[0].shading.color_type = 'OBJECT' return {'FINISHED'} @@ -1392,6 +1398,8 @@ class VisualiseDiff(bpy.types.Operator): obj.color = (0., 1., 0., .2) elif global_id.string_value in diff['changed']: obj.color = (0., 0., 1., .2) + area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') + area.spaces[0].shading.color_type = 'OBJECT' return {'FINISHED'} @@ -3435,3 +3443,16 @@ class AddOpening(bpy.types.Operator): modifier.operation = 'DIFFERENCE' modifier.object = opening return {'FINISHED'} + + +class SetOverrideColour(bpy.types.Operator): + bl_idname = 'bim.set_override_colour' + bl_label = 'Set Override Colour' + + def execute(self, context): + result = 0 + for obj in bpy.context.selected_objects: + obj.color = bpy.context.scene.BIMProperties.override_colour + area = next(area for area in bpy.context.screen.areas if area.type == 'VIEW_3D') + area.spaces[0].shading.color_type = 'OBJECT' + return {'FINISHED'} diff --git a/src/ifcblenderexport/blenderbim/bim/prop.py b/src/ifcblenderexport/blenderbim/bim/prop.py index a089c6c9a8..8368a1e414 100644 --- a/src/ifcblenderexport/blenderbim/bim/prop.py +++ b/src/ifcblenderexport/blenderbim/bim/prop.py @@ -1099,6 +1099,7 @@ class BIMProperties(PropertyGroup): qto_result: StringProperty(default='', name='Qto Result') area_unit: StringProperty(default='', name='IFC Area Unit') volume_unit: StringProperty(default='', name='IFC Volume Unit') + override_colour: FloatVectorProperty(name='Override Colour', subtype='COLOR', default=(1, 0, 0, 1), min=0.0, max=1.0, size=4) class BCFProperties(PropertyGroup): diff --git a/src/ifcblenderexport/blenderbim/bim/ui.py b/src/ifcblenderexport/blenderbim/bim/ui.py index ddc8cecbc9..d2985695c9 100644 --- a/src/ifcblenderexport/blenderbim/bim/ui.py +++ b/src/ifcblenderexport/blenderbim/bim/ui.py @@ -1866,6 +1866,23 @@ class BIM_PT_qto_utilities(Panel): row.operator("bim.calculate_object_volumes") +class BIM_PT_misc_utilities(Panel): + bl_idname = "BIM_PT_misc_utilities" + bl_label = "Miscellaneous" + bl_space_type = 'VIEW_3D' + bl_region_type = "UI" + bl_category = 'BlenderBIM' + + def draw(self, context): + layout = self.layout + props = context.scene.BIMProperties + + row = layout.row() + row.prop(props, 'override_colour', text='') + row = layout.row(align=True) + row.operator("bim.set_override_colour") + + def ifc_units(self, context): scene = context.scene props = context.scene.BIMProperties