0

I am quite new to Maya, and I'd like to make some small tests, in this case, coloring a cube by assigning each vertex a color. Reading the documentation I've come to this small code:

import maya.cmds as cmds

cmds.polyCube(sx=2, sy=3, sz=2, h=3, name='testobj')

tot = cmds.polyEvaluate(v=True, f=False) 

print "vertex count =", tot

for i in range(tot):
    cmds.select('testobj.vtx[' + str(i) + ']')
    v = cmds.pointPosition('testobj.pt[%d]' % i)
    print v, type(v)
    cmds.polyColorPerVertex('testobj.vtx[%d]'%i, colorR=1.0, colorG=0.3, colorB=0.8)

#rgb=((1.5+v[0])/3.0, 0.3, 0.8)
#cmds.polyColorPerVertex('pTorusShape1.vtx[%d]'%vertNum,r=r,g=g,b=b);

cmds.refresh()

The code won't change any color in the scene. I've followed of course the original docs, this SO question, and this code.

I missing something really basic here, I am sure.

Any hints?

senseiwa
  • 2,369
  • 3
  • 24
  • 47

1 Answers1

2

Your code work exactly like what you want .. You just need to display it :)

add this before refresh

cmds.setAttr("testobjShape.displayColors",  1)
Achayan
  • 5,720
  • 2
  • 39
  • 61