check the script forum there is a script somewhere that can add random colors faces on object
normally you add specific mat with color on object!
select an object
then run this script in text editor
and it will add random color for each face
import bpy
import bmesh
def edit_mode_out():
bpy.ops.object.mode_set(mode = 'OBJECT')
def edit_mode_in():
bpy.ops.object.mode_set(mode = 'EDIT')
edit_mode_out() # go into object mode
ob_act = bpy.context.active_object
me = ob_act.data
# Creates new materials
mat = bpy.data.materials.new('red1')
mat.diffuse_color = ( 1.0, 0.0, 0.0 )
me.materials.append(mat)
mat1 = bpy.data.materials.new('blue1')
mat1.diffuse_color = ( 0.0, 0.0, 1.0 )
me.materials.append(mat1)
mat2 = bpy.data.materials.new('green1')
mat2.diffuse_color = ( 0.0, 1.0, 0.0 )
me.materials.append(mat2)
list_0 = [m.name for m in bpy.data.materials]
print ()
print (' Mat List will be in alphabetical order')
print ()
for i1 in range(0,len(list_0 )):
print (' color =',list_0 [i1],' ',i1)
print ()
print ('List of materials =',list_0)
print ()
colorselect="red1"
mi2 = list_0.index(colorselect)
print ('mi selected color in mat list =',colorselect,' mi2=',mi2)
print ()
colorselect="blue1"
mi = list_0.index(colorselect)
print ()
print ('Note The first color will be added to all the faces by default')
print ()
print ('mi selected color in mat list =',colorselect,' mi=',mi)
print ()
# Note The first color will be added to all the faces by default
# Add a base color to the mesh
# http://www.blender.org/documentation/blender_python_api_2_62_0/contents.html
# http://www.blender.org/documentation/blender_python_api_2_62_0/bpy.types.MeshFace.html?highlight=meshface#bpy.types.MeshFace
# http://www.blender.org/documentation/blender_python_api_2_62_0/bpy.types.MeshPolygon.html?highlight=polygon#bpy.types.MeshPolygon.material_index
me.polygons[0].material_index=2 # add a Red base color to all faces automatically
print ('me.polygons =',me.polygons) # represent number of faces tris quads polygon
print ()
print ('me.polygons =',me.polygons)
print ('polygon lenght =',len(me.polygons)) # number of faces ( 3 + 4+ n )
print ()
print ('me.polygons[0] =',me.polygons[0])
print ()
print ('me.polygons[0].material_index =',me.polygons[0].material_index)
print ()
print ('me.polygons[1].material_index =',me.polygons[1].material_index)
print ()
print ()
print ( 'Note The first color will be added to all the faces by default' )
print ( 'Add a base color to the mesh')
# red blue green
print ()
for p1 in me.polygons: # assign material if faces selected
print ('p1 =',p1,' p1 select =',p1.select)
if p1.select:
print ('before material index =',p1.material_index)
# p1.material_index = mi
p1.material_index = 1
print ('after material index =',p1.material_index)
print ()
print ('me.polygons[0].material_index =',me.polygons[0].material_index)
print ()
print ('me.polygons[1].material_index =',me.polygons[1].material_index)
print ()
print ('faces color =',)
print ()
kk=0
for p1 in me.polygons:
print ('KK=',kk,'material index =',p1.material_index)
kk1=p1.material_index
print (' color = list_0[ ',kk1,'] = ',list_0[kk1])
print (' len verts',len(p1.vertices))
print (' verts',p1.vertices)
for j1 in range(0,len(p1.vertices)):
print ('vert[',j1,']=',p1.vertices[j1])
kk+=1
print ()
bme = bmesh.new()
bme.from_mesh(ob_act.data)
bme.to_mesh(ob_act.data)
edit_mode_in() # go into edit mode
happy bl