Reputation: 37
I did the following steps to create a new material and link it to the object:
I want to change the color randomly using this script:
from random import random
import Blender
from Blender import *
scn = Blender.Scene.GetCurrent()
ob = scn.objects.active
m = ob.getData(mesh=True)
if(len(m.materials) < 1):
mat = Material.New('newMat')
m.materials += [mat] m.materials[0].rgbCol = [random(), random(), random()]
Blender.Redraw()
Why doesn't the color of the object change?
Upvotes: 0
Views: 5645
Reputation: 153
Because, random() returns a number between 0 and 1. I expect rgbcol must be between 0 and 255. try this:
m.materials += [mat]m.materials[0].rgbCol(random()*255, random()*255, random()*255)
it is changing the color, (unless it has some other problem) but the effect is too small to be noticable.
Upvotes: 1