Accessing Vertex Colors

You can get and set vertex colors from the Geometry object by using the VertexColors property and enumerating over them.

Example: adding and finding vertex color

This example demonstrates setting up local material on a mesh sphere, adding vertex colors, and then finding those vertex colors.

' Create a new scene with a sphere
NewScene , false
CreatePrim "Sphere", "MeshSurface"

' Get the selected elements (ie., the sphere)
if Selection.Count = 0 then
   LogMessage "Nothing selected", siError
else
   set oSelectedObjects = Selection

   ' Get selected oMeshes from selection list
   set oMeshes = SIFilter(oSelectedObjects, "polygon_mesh", true, siQuickSearch)

   if oMeshes.Count < 1 then
       LogMessage "No polygon oMeshes selected", siError
   end if

   ' Add 4 vertex color properties to each mesh
   for i = 0 to oSelectedObjects.Count - 1
       ' Get current mesh (type : "polyMsh")
       set oMesh = oSelectedObjects(i)

       ' Get obj material
       set oMaterial = oMesh.Material

       ' If material is not local add one
       if oMaterial.IsA(siSharedPSet) then
          set oMaterial = oMesh.AddMaterial
       end if

       ' Get polygon mesh geometry
       set oPolyGeometry = oMesh.ActivePrimitive.Geometry

       for j = 0 to 3
          oPolyGeometry.AddVertexColor
       next
   next

   ' List all vertex colors installed on polygon oMeshes
   for i = 0 to oSelectedObjects.Count - 1
       ' Get current mesh (type : "polyMsh")
       set oMesh = oSelectedObjects(i)

       ' Get polygon mesh geometry
       set oPolyGeometry = oMesh.ActivePrimitive.Geometry

       set oVertexColors = oPolyGeometry.VertexColors
       LogMessage oVertexColors.Count

       for j = 0 to oVertexColors.Count - 1
          set oVtxColor = oVertexColors(j)
          LogMessage oVtxColor.FullName
       next
   next
end if

' Output of above script:
'INFO : "4"
'INFO : "sphere.polymsh.cls.UV_Cluster_AUTO.Vertex_Color"
'INFO : "sphere.polymsh.cls.UV_Cluster_AUTO.Vertex_Color1"
'INFO : "sphere.polymsh.cls.UV_Cluster_AUTO.Vertex_Color2"
'INFO : "sphere.polymsh.cls.UV_Cluster_AUTO.Vertex_Color3"


Autodesk Softimage v7.5