1

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.

user824624
  • 269
  • 1
  • 7
  • 20
  • Do you want to set the viewport color or material color? – TLousky Oct 13 '15 at 06:34
  • Object.color doesn't work for Cycles Renderer. – zeffii Oct 13 '15 at 07:56
  • 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. – batFINGER Oct 13 '15 at 07:57
  • Your function works generally, but to see the effects, you need to turn object color on: http://blender.stackexchange.com/questions/7792/how-to-show-an-object-in-the-3d-view-as-a-specific-color – TLousky Oct 13 '15 at 07:57
  • Thanks,@TLousky, it works well for me, could you put the answer, so I can give the reward on the answer – user824624 Oct 13 '15 at 12:00

0 Answers0