Trouble setting vert colours from python.

I am having trouble setting vertex colours in blender through python.

I am writing a 3dsmax import script that is 90% done but the vert colours are not showing the the final imported mesh.

the command that docs keep talking about…

someNMesh.has_col = 1

#…gives an error and looks like it has been removed.

Could sombody write an example script that creates a NMesh quad or tri - and add vert colours to it.

The problem seems to be that I cant change the flag has_col flag

If I use a mesh that has vartex colours I am able to ghange the colours in python but If I create the mesh the default is not to use vertex colours and I don’t know how to enable them.

There is a bug in this part of the NMesh system.

You can’t add colours without uvcoords (or you have to use
a very old Blender version).
Try to find (look at the “list scripts effort”) the Scorpius’
displacement map script in which there is an explanation
of the method to correct this problem

Thanks, I spent a long time on that one.
By th way.

x.has_col=1 and x.has_uvco=1

have been replaced by
x.hasVertexColours() and x.hasVertexUV

Quite…

In fact, I do not remenber if you can change the values
with those two functions. They seem to only return
the state of the mesh.

YAY! Got it working- here is my script. Hope its of help

import Blender
from Blender import NMesh

mesh = NMesh.GetRaw()

Make 3 verts

mesh.verts.append(NMesh.Vert(0,1,1))
mesh.verts.append(NMesh.Vert(1,0,1))
mesh.verts.append(NMesh.Vert(0,0,0))

make a triangle out of the verts

face = NMesh.Face()
face.v.append(mesh.verts[0])
face.v.append(mesh.verts[1])
face.v.append(mesh.verts[2])

Add the face to the mesh

mesh.faces.append(face)

##################

PAINT THE FACE

##################

Make 3 colours

red = NMesh.Col(255,0,0,255)
green = NMesh.Col(0,255,0,255)
blue = NMesh.Col(0,0,255,255)

##############################################################

BUG SHOULD NOT NEED TO SET UV COORDS FOR VERTCOL TO WORK

##############################################################

mesh.faces[0].uv = [(0,0), (0,0), (0,0)]

Set the face some colours

mesh.faces[0].col = [red, green, blue]

Put the mesh into the scene

NMesh.PutRaw(mesh, “testmesh”)