0

I know you can query which camera is associated with a particular panel. But, is there a way you can do it the other way around?

I want to be able to see what panel is associate with a particular camera.

Example:

getPanel -q mainCamera;

// modelPanel1

Thanks for the help yall

por4por
  • 35
  • 6
  • Did you meant **camera is associated with a particular panel** instead of **camera is associated with a particular camera** in your first sentence? – DrHaze Apr 02 '15 at 11:00

2 Answers2

2

This script returns which panels are associated with a particular camera (in this case: persp).

Mel version:

proc string[] getPanelFromCamera(string $cameraName){
    string $listPanel[];
    for( $panelName in `getPanel -type modelPanel`){
        if( `modelPanel -query -camera $panelName` == $cameraName){
            $listPanel[size($listPanel)] = $panelName;
        }
    }
    return $listPanel;
}

print `getPanelFromCamera("persp")`;

Python version:

import maya.cmds as cmds

def getPanelFromCamera(cameraName):
    listPanel=[]
    for panelName in cmds.getPanel( type="modelPanel" ):
        if cmds.modelPanel( panelName,query=True, camera=True) == cameraName:
            listPanel.append( panelName )
    return listPanel

print getPanelFromCamera("persp")

Note: I'm usually don't script in mel, so the mel version of this code is a litteral translation from the python version. I also thought that the Python version might be useful for future readers.

DrHaze
  • 1,318
  • 10
  • 22
  • This works great. Thank you for even deciphering my bad English. Do you know if there is a way to use unique camera names on the "modelPanel -query -camera $panelName." If there are two cameras with the same name it doesn't work. It doesn't work with "|cameraName" either.. – por4por Apr 02 '15 at 21:06
  • Something strange, if there are two cameras with the same name. (|camName & |group1|camName) then the "modelPanel -query -camera |camName" will accept "|" – por4por Apr 02 '15 at 21:16
0

If you have the panel, and you want the camera associated with it, you can simply query it

import maya.cmds as cmds
cmds.modelPanel("modelPanel1", query=True, camera=True)
user1767754
  • 23,311
  • 18
  • 141
  • 164