Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/291.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PYTHON中的渲染层中查找选定网格的材质_Python_Maya - Fatal编程技术网

在PYTHON中的渲染层中查找选定网格的材质

在PYTHON中的渲染层中查找选定网格的材质,python,maya,Python,Maya,我尝试在添加的每个渲染层中获取选定网格的材质名称,而不切换渲染层。 但是,我得到了这个错误:TypeError:RenderLayer类型的对象没有len()# 从对象获取材质的代码: import pymel.core as pm import maya.cmds as cmds # Create a dictionary for {"object1": ["material1", "material2"]} objectToMate

我尝试在添加的每个渲染层中获取选定网格的材质名称,而不切换渲染层。 但是,我得到了这个错误:TypeError:RenderLayer类型的对象没有len()#

从对象获取材质的代码:

import pymel.core as pm
import maya.cmds as cmds
# Create a dictionary for {"object1": ["material1", "material2"]}
objectToMaterials = {}
for obj in pm.ls(sl=1):
    for layer in obj.listConnections(type="renderLayer"):
        print 'object: %s  layer: %s' % (obj, layer )  # result:     object: pSphere1  layer: layer3
        allChildren = cmds.listRelatives(ad=1)
        for eachChild in allChildren:
            if cmds.objectType(eachChild)=="mesh":
                eachChild = cmds.listRelatives(eachChild, parent=1)
                print eachChild # result:     [u'pSphere1']
                print layer  # result:      layer3
                cmds.editRenderLayerGlobals(crl=layer)  # result:   TypeError: object of type 'RenderLayer' has no len() # 
                # Get the shader groups attached to this particular object
                shaderGroups = cmds.listConnections(cmds.listHistory(eachChild))
                if shaderGroups is not None:
                    # Get the material attached to the shader group
                    materials = [x for x in cmds.ls(cmds.listConnections(shaderGroups), materials=1)]       
                objectToMaterials.setdefault(eachChild[0], []).append(eachRenderLayer)
                objectToMaterials.setdefault(eachChild[0], []).append(materials[0])
print(objectToMaterials)