Changing polygons' colors in Maya via Python -


the way know use slider:

import maya.cmds cmds  cmds.colorslidergrp( 'polygoncolour', label = "colour", hsv = ( 1, 1, 1 ) ) 

then taking rgb value that:

rgb = cmds.colorslidergrp( 'polygoncolour', query = true, rgbvalue = true ) 

and assigning material polygon , giving material color:

myshader = cmds.shadingnode( 'lambert', asshader = true, name = "polygonmaterial" ) cmds.setattr( 'polygon1' + ":blockmaterial.color", rgb[ 0 ], rgb[ 1 ], rgb[ 2 ], type = 'double3' ) 

is there easier approach without using slider and/or without assigning material?

if want assign new color existing shader(s), it's simple setattr(). every shader has it's own attribute set, exact values need set depend on type of shader want, common cases (lambert, phong, , blinn) it's .color attribute. setting color simple passing in rgb values want:

 cmds.setattr(shader + '.color', 0, 1, 0)  # green 

getting shader on particular face not easy. easiest thing face , check shadingengine nodes :

 shadingengine in cmds.ls(type="shadingengine"):      if cmds.sets('pcube1.f[0]', im=shadingengine):         shaderball = cmds.listconnections(sshadingengine, type = 'lambert')[0]         print "face assigned %s" % shaderball 

you can assign shader face cmds.sets('pcube1.f[99]', fe='initialshadinggroup')

where argument fe shadingengine node. shader ball - thing edit hand - connected shadingengine's .surfacematerial attribute, can way did above.

if want change color of face without shader assignment want make vertex colors instead. menu color > apply color, command polycolorpervertex (faces, rgb=(r,g,b). setting color of 1 face on cube looks

 cmds.polycolorpervertex('pcube1', rgb=(1,0,0)) # red 

the display of vertex colors in viewport controlled .displaycolors attribute or colors > toggle display colors attribute menu item.


Comments

Popular posts from this blog

node.js - Mongoose: Cast to ObjectId failed for value on newly created object after setting the value -

gradle error "Cannot convert the provided notation to a File or URI" -

python - NameError: name 'subprocess' is not defined -