4
$\begingroup$

How send HSV value to color picker in Blender from Python console? By default we can send only RGB :(

$\endgroup$
1
  • $\begingroup$ How about using a script with a function that converts HSV to RGB? You would have to execute the script instead of entering the command in the console. $\endgroup$
    – maddin45
    Commented May 23, 2014 at 23:17

1 Answer 1

8
$\begingroup$

You can use the mathutils.Color type to convert HSV to RGB:

from mathutils import Color

c = Color()
c.hsv = 0.0833, 0.4, 0.5

print(c)
# roughly Color((0.5, 0.4, 0.3))

If you want to assign the color to a RGBA property (4 floats), you need to either do:

bpy.context.object.color = c.r, c.g, c.b, 1.0 # 1.0 is alpha

or a bit ugly looking tuple concatenation:

bpy.context.object.color = c[:] + (1.0,)

Alternatively, import the Python standard library module colorsys and use its conversion functions:

import colorsys

colorsys.hsv_to_rgb(0.0833, 0.4, 0.5)
# (0.5, 0.39996, 0.3)
$\endgroup$
2
  • $\begingroup$ Thank you very much CoDEmanX! I have one more question: How refresh color picker element, after I set new value? $\endgroup$
    – AronBlend
    Commented May 25, 2014 at 9:38
  • $\begingroup$ If it doesn't update automatically, flag it to let Blender refresh it by calling Region.tag_redarw() on the editor region where the property is shown in. $\endgroup$
    – CodeManX
    Commented May 25, 2014 at 21:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .