1
$\begingroup$

In python program, I want to randomly give the color to a object, I found a snippet like this

def get_random_color():
    ''' generate rgb using a list comprehension '''
    r, g, b = [random.random() for i in range(3)]
    return r, g, b, 1

bpy.data.objects['object'].color = get_random_color()

however this doesn't work for me, my environment is OSX 10.10 and blender 2.7.6.

$\endgroup$
5
  • $\begingroup$ Do you want to set the viewport color or material color? $\endgroup$
    – TLousky
    Oct 13, 2015 at 6:34
  • $\begingroup$ Object.color doesn't work for Cycles Renderer. $\endgroup$
    – zeffii
    Oct 13, 2015 at 7:56
  • $\begingroup$ Can you add the error message? The get_random_color() method works fine for me. Do you have an object named "object"? have you imported random etc. $\endgroup$
    – batFINGER
    Oct 13, 2015 at 7:57
  • $\begingroup$ Your function works generally, but to see the effects, you need to turn object color on: blender.stackexchange.com/questions/7792/… $\endgroup$
    – TLousky
    Oct 13, 2015 at 7:57
  • $\begingroup$ Thanks,@TLousky, it works well for me, could you put the answer, so I can give the reward on the answer $\endgroup$
    – user824624
    Oct 13, 2015 at 12:00

0

You must log in to answer this question.

Browse other questions tagged .