我应该如何在五月将imagePlane的形状节点连接到camera

2024-09-29 21:35:37 发布

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

def connectedImgPlanes(self,dagNode):
    print "dagNode ",dagNode ,type(dagNode)
    sourceConnections = cmds.listConnections(dagNode, source = True) or []
    if len(sourceConnections) != 0:
       lc = sourceConnections[0].split("->")[1]
       atribVal=cmds.getAttr(lc+".imageName")
       return atribVal
    else:
        return ""

上面的函数起作用,并从imageplane的shape节点的imageName属性返回文件名路径,但是如果top camera设置了imageplane,那么上面的函数就不起作用了,在这种情况下,我得到一个错误消息:error:line 1:IndexError:file line 1:list index out of range#,原因是

^{pr2}$

然后我尝试了不同的方法来获取imageplanes的shape节点并从中返回一个属性

    lc=""
    try:
        lc=cmds.listRelatives(cmds.listRelatives(dagNode)[0])[0]
    except TypeError:
           return ""
    print lc
    atribVal=cmds.getAttr(lc+".imageName")
    return atribVal

这个方法同样有效,直到我们添加了顶部摄像头,并且代码开始给出不同类型的错误,说明有多个对象与名称匹配:imagePlane1#

请有人帮我得到每个相机的形状节点,并返回空字符串,如果相机没有设置图像平面。。。在


Tags: 函数return属性节点错误lcprintshape
1条回答
网友
1楼 · 发布于 2024-09-29 21:35:37

由于imagePlanes(dependNode)不能有任何shape节点,因此我假设它是您想要的imageName属性。在

下面的函数,如果传递了camera,将返回附加到它的任何imagePlaneimageName属性。如果传递了一个transform,它将查找到它的任何camera连接,然后返回找到的相机上任何imagePlanesimageName属性。在

import maya.cmds as cmds 

def connectedImgPlanes(dagNode):
    # if we have camera transform then go to camera shape 
    if cmds.nodeType(dagNode) == 'transform':
        dagNode = cmds.listRelatives(dagNode, s=True, c=True)[0]
    if cmds.nodeType(dagNode) != 'camera': 
        cmds.error("%s is not a camera node" %dagNode)

    # get all the imageplane nodes connected to image plane
    sourceConnections = cmds.listConnections(dagNode + '.imagePlane', source = True, type = 'imagePlane') or []

    # collect all the 'imageName(s)' into a list and return it
    imageNames = []
    for lc in sourceConnections:
       atribVal=cmds.getAttr(lc+".imageName")
       imageNames.append(atribVal)
    return imageNames

相关问题 更多 >

    热门问题