Take the 2-minute tour ×
Blender Stack Exchange is a question and answer site for people who use Blender to create 3D graphics, animations, or games. It's 100% free, no registration required.

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

share|improve this question
    
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. –  maddin45 May 23 at 23:17

1 Answer 1

up vote 3 down vote accepted

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)
share|improve this answer
    
Thank you very much CoDEmanX! I have one more question: How refresh color picker element, after I set new value? –  AronBlend May 25 at 9:38
    
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. –  CoDEmanX May 25 at 21:46

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.