在五月将着色器存储为Python的变量

2024-09-28 05:22:08 发布

您现在位置:Python中文网/ 问答频道 /正文

我在Maya中有一个脚本,它会查找着色器并在该着色器不存在时创建它。到目前为止,还不错。问题是,当它被找到时,我似乎无法让玛雅从它的名字存储它。你知道吗

import maya.cmds as cmds

findShd = cmds.objExists( 'shd_' + str( udim ) )

    if findShd:
        print 'shader exists'
        shaders = cmds.ls( 'shd_' + str( udim ) )
        print shaders[ 0 ] # this prints the name as I would expect
        shaderSG = mc.listConnections( shaders[ 0 ], type = 'shadingEngine' )

    else:
        shader = cmds.shadingNode( 'blinn', asShader = True, name = ( 'shd_' + str( udim ) ) )
        shaderSG = cmds.sets( shader, renderable = True, noSurfaceShader = True, empty = True, name = shader + "SG" )
        cmds.connectAttr( shader + ".outColor", shaderSG + ".surfaceShader", force = True )         
        cmds.select( shellUVs )
        lFaces = cmds.ls( cmds.polyListComponentConversion( tf = True ) )

        for face in lFaces:         
            cmds.sets( lFaces, e = True, forceElement = shaderSG )

当着色器存在时,我需要同时存储它和它所附加的着色组,以便在条件之外指定它。你知道吗

但这一行:

shaderSG = cmds.listConnections( shaders[ 0 ], type = 'shadingEngine' )

给我:Module object has no attribute listConnections

如果没有列表,我应该如何存储它?你知道吗

谢谢。你知道吗


Tags: nametrueas着色器printcmdsstrshader

热门问题