maya - python - get the assigned shader from material


#1

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.
cheers
Bastian


#2

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')


:nathaN


#3

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.


#4

erm… thanks. I think? :smiley:


#5

^^ hehe!

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

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

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


#6

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.