Search code examples
pythonif-statementruntime-errormaya

How to query if Camera has Image plane.py


I am trying to figure out how to query if a camera has an image plane. Right now i am using this code to find out what the name of the image plane is but, if 'persp' doesn't have an image plane it errors out with:

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

if someone can help me understand how i can get it to check if the camera has an image plane before it errors out.

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`

Thanks, Adam


Solution

  • You can check if there is any iplane then do the stuff or make empty list

    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