0

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?

Community
  • 1
  • 1
shaimaa
  • 37
  • 1
  • 3
  • 9

1 Answers1

1

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.

Connor Hull
  • 133
  • 1
  • 1
  • 5