Maya Python IF statement: Coloring Faces

import maya.cmds as cmds
cmds.polyTorus() #create a polygonal torus
facesnr=cmds.polyEvaluate(f=True) #find out the number of torus faces

 
for i in range(facesnr):
box1=cmds.xform('pTorus1.f[%d]'%i,q=1,bb=1)
if box1[1]>.2:
cmds.select('pTorus1.f[%d]'%i)
cmds.hyperShade(assign='blinn1')

box1 store the bounding boxes of the torus faces.
The values are in the following order: xmin ymin zmin xmax ymax zmax. We compare ymin with .2 and we color the upper faces by a blinn shader. If we want to use 2 different blinn colors we write :

  
cmds.select('pTorus1.f[%d]'%i)
if box1[1]>.2:
cmds.hyperShade(assign='blinn1')
else:
cmds.hyperShade(assign='blinn2')

Leave a comment

Your email address will not be published. Required fields are marked *