How can I get all of the shaders/materials from a single mesh?
We have 2 scenarios:
1. mesh can have a single shader/material
2. mesh can have multiple shaders/materials (due to combining nodes).
This is what we do to get a single shader from a mesh
CODE
#========================================================================
def GetShaderFromMesh (mesh):
future = mayaCmd.listHistory(str(mesh), f=1, pdo=1)
if future is None:
return None
# Search for the connecting shading group
for n in future:
if mayaCmd.attributeQuery("surfaceShader",node=n, exists=True):
# Get shader from incoming connection of the shading group
shader = mayaCmd.listConnections("%s.surfaceShader" % (str(n)), source=True)
if shader is None:
continue
shader = str(shader[0])
return None
Thanks in advance!
created
Feb '08
last reply
Jul '18
- 4
replies
- 11.2k
views
- 1
user