-1

I need to print each shave shape and its assigned shader name if assigned. Please help in this.

import os
import maya.cmds as cmds
shave_list = cmds.ls(type='shaveHair')
cmds.select(cl=True)
a = 0
list_texture = []
while a < len(shave_list):
    file_list = cmds.listconnections(shave_list[a],type="file")
    a+=1
Murali
  • 23
  • 4

1 Answers1

0

If you want the shader name for a shape:

def shader_from_shape(shape):
    sg = cmds.listConnections(shape, type='shadingEngine')
    if sg:
        return cmds.listConnections(sg[0]  + ".surfaceShader")

and to get the shaders for all hair shapes:

for shape in cmds.ls(type='shaveHair'):
    print shape, shader_from_shape(shape)

if the shape has no shader attached, it should print None for the shader. This won't give correct results if the shape has more than one shader - I'm not sure if that's possible or not.

theodox
  • 12,028
  • 3
  • 23
  • 36