maya - python - get the assigned shader from material


hey ppl.

anyone ever got the assigned shader to the current selected object?

like the hypershade command under edit: select materials from object.

maybe there is a easier way than tracing to the shadinggroup from the shape and back into the material.

thanks for pointing me out.
really stuck on that one.


unfortunately, shaders and objects are not connected so you have to go via the ShadingGroup set.

this does it in one line:

shaders = cmds.listConnections(cmds.listHistory('pCube1',f=1),type='lambert')



interesting way, thangs nathan.
may the almighty godess of coding bless you with some of the unspoken and nevertold classes for THE unbreakable - neverending infinity loop of immortality.


erm… thanks. I think? :smiley:


^^ hehe!

of course only with the help of nathan as well I just scripted sth similar on this thread.

# get shapes of selection:
shapesInSel =,o=1,s=1,sl=1)
# get shading groups from shapes:
shadingGrps = mc.listConnections(shapesInSel,type='shadingEngine')
# get the shaders:
shaders =,materials=1)

no one liner but … just wanted to point out that I always filter the resulting connections through ls -materials / because not every shader is derrived from lambert.(I know there are only a few exceptions but… )


This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.