I've seen a lot of variations of using color pickers, but I want to see just a simple, clear example of being able to bring up a color picker (with a default color set), pick a color, and being able to get the value from that color picker either as a return value after it's picked, or being able to access that value at another time.
One resource that has helped me some is this answer on another SE:Blender question. In that case, the script provided 5 color pickers. I edited it some, both to help me understand it and to make it work as just a single color picker:
import bpy class ColorItem(bpy.types.PropertyGroup): color = bpy.props.FloatVectorProperty( name = "Color Picker", subtype = "COLOR", size = 4, min = 0.0, max = 1.0, default = (1.0,1.0,1.0,1.0) ) class ColorPanel(bpy.types.Panel): """Creates a Panel in the Scene properties window""" bl_label = "Colors" bl_idname = "SCENE_PT_colors" bl_space_type = 'PROPERTIES' bl_region_type = 'WINDOW' bl_context = "scene" def draw(self, context): row = self.layout.row() row.prop(context.scene.colors, "color", text='Pick Color') def register(): bpy.utils.register_class(ColorPanel) bpy.utils.register_class(ColorItem) def unregister(): bpy.utils.unregister_class(ColorPanel) bpy.utils.unregister_class(ColorItem) if __name__ == "__main__": register() bpy.types.Scene.colors = bpy.props.CollectionProperty(type=ColorItem) bpy.context.scene.colors.add()
While just a simple example would provide me with what I need (again, with me being able to set the default color and being able to get the color value either as a return value or to get it when I need it), there are parts in this script I don't understand and would like to. Also, on that 2nd to last line, I'm not sure just how the object creation is done. By passing "type=ColorItem" to bpy.props.CollectionProperty(), is it returning an object of that class? (I'm assuming it does, but realize I don't understand all that's going on there.)
Also, on the last line, just what is being added to bpy.context.scene.colors?
I don't see the difference (in the last part) between "Scene" (2nd to last line) and using "scene," but capitalizing it instead of keeping it lower case. There's also the object in the draw subroutine context.scene.colors. Are they the same object?
When I've tried to figure out just what kind of object I'm working with, even with the ColorItem class in this code, I'm not clear how there are 16 of this item, and not just one, and why that class is not just a single floating point vector with 4 parts that makes up the color.
Any explanation of this that would clarify things for me would be a big help.