如何查询Camera是否有Image plane.py

How to query if Camera has Image plane.py

我想知道如何查询相机是否有图像平面。 现在我正在使用这段代码来找出图像平面的名称,但是,如果 'persp' 没有图像平面,它会出错:

line 2: 'NoneType' object has no attribute '__getitem__' #

如果有人可以帮助我了解如何让它在出错之前检查相机是否有图像平面。

1: camShape = cmds.listRelatives('persp', type='camera', fullPath=True)[0]
2: ip = cmds.listConnections(camShape, type="imagePlane")[0]
3: ImageName = ip.split('>')[+1]
4: print ImageName`

谢谢, 亚当

您可以检查是否有任何 iplane 然后执行这些操作或创建空列表

camShape = cmds.listRelatives('persp', type='camera', fullPath=True)[0]
ip = cmds.listConnections(camShape, type="imagePlane") or []
if ip:
    ImageName = ip[0].split('>')[+1]
    print ImageName