shaimaa
shaimaa

Reputation: 37

changing the color of object in blender

I did the following steps to create a new material and link it to the object:

  1. Select an object.
  2. In Button window (at bottom) select 'Shading' (a gray ball) and then 'Material buttons' (red ball)
  3. In 'Link and pipeline', press 'Add new'.
  4. Edit material color ('Col').

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

Answers (1)

Connor Hull
Connor Hull

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

Related Questions