# How to store the color of Colorpickers

I made a piemenu where you can select colors with a colorpicker. I would like to store the picked color in an attribute that I can access. In File>User Preferences>Themes it seems like it can be stored in attributes such as 'ThemeBoneColorSet.normal'. I don't know how to make such attributes myself nor how to access them to store the output.

The relevant lines of code that specify the output of the color picker (I can't find that brush, code from this answer):

def draw(self, context):
ts = context.tool_settings
ups = ts.unified_paint_settings
ptr = ups if ups.use_unified_color else ts.image_paint.brush


The current version of the piemenu and the script that produces it (note that you may not get the buttons as I specify them in a different addon):

import bpy

# spawn an edit mode selection pie (run while object is in edit mode to get a valid output)

class Carpaint(bpy.types.Operator):
bl_idname = "wm.carpaint"
bl_label = "Carpaint"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class FrontLights(bpy.types.Operator):
bl_idname = "wm.frontlights"
bl_label = "FrontLights"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}
class BackLights(bpy.types.Operator):
bl_idname = "wm.backlights"
bl_label = "BackLights"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class Wheels(bpy.types.Operator):
bl_idname = "wm.wheels"
bl_label = "Wheels"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class Rims(bpy.types.Operator):
bl_idname = "wm.rims"
bl_label = "Rims"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class MetalParts(bpy.types.Operator):
bl_idname = "wm.metalparts"
bl_label = "MetalParts"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class test(bpy.types.Operator):
bl_idname = "wm.test"
bl_label = "TestTest"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class Windows(bpy.types.Operator):
bl_idname = "wm.windows"
bl_label = "Windows"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

class Plastic(bpy.types.Operator):
bl_idname = "wm.plastic"
bl_label = "Plastic"

def execute(self, context):
scene = context.scene
mytool = scene.my_tool

return {'FINISHED'}

bl_label = 'Set Colours'
bl_idname = 'OBJECT_MT_colour_pie'

def draw(self, context):
ts = context.tool_settings
ups = ts.unified_paint_settings
ptr = ups if ups.use_unified_color else ts.image_paint.brush
#ptr = bpy.context.object.active_material.diffuse_color

base = pie.row()
col = base.column()
row0 = col.row()
row1 = col.row()
row2 = col.row()
row3 = col.row()
row4 = col.row()
row5 = col.row()
row6 = col.row()
row7 = col.row()

row0.prop(ptr, 'color')
row0.operator('wm.carpaint')

row1.prop(ptr, 'color')
row1.operator('wm.frontlights')

row2.prop(ptr, 'color')
row2.operator('wm.backlights')

row3.prop(ptr, 'color')
row3.operator('wm.windows')

row4.prop(ptr, 'color')
row4.operator('wm.wheels')

row5.prop(ptr, 'color')
row5.operator('wm.rims')

row6.prop(ptr, 'color')
row6.operator('wm.metalparts')

row7.prop(ptr, 'color')
row7.operator('wm.plastic')

def register():
bpy.utils.register_class(ColourPie)

def unregister():
bpy.utils.unregister_class(ColourPie)

if __name__ == "__main__":
register()


• The example from Themes shows the values of different color properties ((Regular outline etc). The color is not stored in the picker it is the value of the property. Your example are all the same since ts0 = ts1 = ts2 = context.tool_settings – batFINGER Sep 11 '18 at 13:38
• @WhatAMesh You might find this answer helpful. Normally you store these properties just on static properties of your operator, and then draw them in the draw function with layout.prop(). But there's a second way in that answer that may also work for you. – Coburn Sep 13 '18 at 2:37