Getting name of the imageplane to selected camera

is it possible pythonically to get the name of the imageplane node of the selected camera ?
I have managed to code to get the modelPanel name and get its camera

import maya.cmds as cmds
p=cmds.getPanel(wf=True)
print("Panel in foucs: ",str(p))
cam=str(cmds.modelEditor (p, q=True, camera=True))
print("Camera: ",cam)
cmds.select(cam)
print(cmds.pickWalk(direction='down' )[0])

now how can I get the name of imagePlane that is connected to the camera…

The way I’ve done this earlier is to use “listConnections”… As long as two nodes are connected somehow, you can always find it this way.


list = cmds.listConnections('perspShape')

but the possibility remains their can be other different type of connections to camera and since its a list , the list could then be populated with other type of objects as well then what…

One simple way would be to check the type of the connected nodes. If its node type is ‘imagePlane’, it’s probably an image plane.

Since you can have multiple image planes on a single camera, this function returns a list:

import maya.cmds as cmds

def GetImagePlanes(cameraShape):
    """
    Returns a list of image plane nodes connected to the given camera shape
    node. If no image planes are connected, returns an empty list.
    """
    assert cmds.nodeType(cameraShape) == 'camera'
    
    sourceConnections = cmds.listConnections(cameraShape, source = True) or []
    return [node for node in sourceConnections if cmds.nodeType(node) == 'imagePlane']

or perhaps
cmds.listConnections( type=‘imagePlane’ )

Ah, my rustiness with Maya is showing. Yes, that makes a lot more sense ^

I came up with simple one though:

print(cmds.listConnections('frontShape.imagePlane', s=True, d=False)[0])

Howzzat !!!