here is a few function that should get you going:in short, you create a
shader and a shading group, connect the shader to the shading group
Then connecting an object or polygon face(s) to the set will assign the
shader to the objects/faces

good luck

import maya.cmds as mc
""" create a new shader """
def createShader(shaderType='lambert', name=''):
if name == '':
name = shaderType
name = mc.shadingNode(shaderType, asShader=True,  name=name)
sg = mc.sets(renderable=True, noSurfaceShader=True, empty=True, name='%sSG'
%(name))

# connect shader to SG
shaderOutput = 'outValue'
if shaderType== 'mia_material' or shaderType == 'mia_material_x':
if shaderType == 'mia_material_x':
shaderOutput = "result";
mc.connectAttr('%s.%s' %(name,shaderOutput), '%s.miMaterialShader' %(sg),
force=True)
mc.connectAttr('%s.%s' %(name,shaderOutput), '%s.miShadowShader' %(sg),
force=True)
mc.connectAttr('%s.%s' %(name,shaderOutput), '%s.miPhotonShader' %(sg),
force=True)
else:
mc.connectAttr('%s.outColor' %(name), '%s.surfaceShader' %(sg), force=True)
 return [name, sg]

def assignToShader(shaderSG=None, objects=None):
# assign selection to the shader
if objects is None:
objects = mc.ls(sl=True, l=True)
for i in objects:
print i
try:
mc.sets(i, e=True, forceElement=shaderSG)
except:
pass

"""
Example:
# run the next line
shader, shaderSG = createShader('blinn', 'foobar')
# SELECT SOME OBJECTS
# run the next line to assign the selected object to the shader
assignToShader(shaderSG)


On Mon, Apr 20, 2009 at 3:54 PM, mariejoa...@gmail.com <
mariejoa...@gmail.com> wrote:

>
> I have a cylinder I created with polyCylinder which I'd like to assign
> a color to (no texture, just a color). I figured I had to create a new
> material first since I'd like to create many such polygons with a
> different color each. Then I'd connect it to the polygon and modify
> the color.
>
> The problem is that I'm stuck at 'creating a new material', I can't
> find anything like this in the documentation (or maybe I'm just not
> understanding).
>
> Any help?
>
> P.S.: I'm stuck on Maya 8.5, this is all the school have licensed.
>
> Thanks
>
> >
>


-- 
They say, "Evil prevails when good men fail to act." What they ought to say
is, "Evil prevails."
Nicolas Cage as Yuri Orlov in Lord of War.

--~--~---------~--~----~------------~-------~--~----~
http://groups.google.com/group/python_inside_maya
-~----------~----~----~----~------~----~------~--~---

Reply via email to