0
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的形状节点的imageName属性返回带有文件名的路径,但是如果顶部相机设置了imageplane,那么上面的函数不起作用,在这种情况下我得到错误说# Error: line 1: IndexError:文件第 1 行:列表索引超出范围 #由于

newStr=str(sourceConnections[0]).split("->")[1]

然后我尝试了不同的方法来获取图像平面的形状节点并从中返回一个属性,

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

这个也可以工作,直到我们添加顶部相机并且代码开始给出不同类型的错误,说多个对象匹配名称:imagePlane1 #

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

4

1 回答 1

0

由于imagePlanes(dependNode) 不能shape附加任何节点,因此我假设它是您想要的imageNameattr 。imagePlane

以下函数,如果传递 a camera,将返回imageName任何imagePlane附加到它的属性。如果 atransform被传递,将寻找任何camera与它的连接,然后返回任何附加到找到的相机的imageName属性。imagePlanes

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
于 2012-10-21T21:19:08.710 回答