Template Number Input and Template Color Picker

Hi everyone

I am coding a personal add-on that can control some color in 3D view without open shader editor. And I just saw someone suggest use template for color ramp like:

layout.template_color_ramp(bpy.data.worlds["World"].node_tree.nodes["Sky Color"], "color_ramp", expand=True)

Its work, then I try to use color picker like:
layout.template_color_picker(bpy.data.scenes["Scene"].eevee.bloom_color, "color_picker", expand=False)
and got a error:
UILayout.template_color_picker(): error with argument 1, "data" - Function.data expected a AnyType type, not Color

Is there any way to use number input (float, int) and color picker as template that point directly to the available data? The document dont have any example and I cant find any example on internet. With this way its will shorten the code and make it more clearly.

doc link: https://docs.blender.org/api/current/bpy.types.UILayout.html

Thank you for your support!

The arguments to template_color_picker are the data and then the property, so

layout.template_color_picker(bpy.data.scenes["Scene"].eevee, "bloom_color")
or if you want the saturation slider too:
layout.prop(bpy.data.scenes["Scene"].eevee, "bloom_color", value_slider=True)

If you just want to copy an existing color widget into your panel you can use prop:
layout.prop(bpy.data.scenes["Scene"].eevee, "bloom_color")
and you can rename it with the text argument:
layout.prop(bpy.data.scenes["Scene"].eevee, "bloom_color", text="Bloom color")

1 Like

Wow, I don’t see anyone suggest to use prop in a cool way like that
Thank you so much!