Home Technical Talk

How to query RenderView's current camera?

polycounter lvl 11
Offline / Send Message
Toast polycounter lvl 11
Hi, is it possible to query this exact value in MEL somehow? Surely Maya is storing this setting somewhere!

Replies

  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    no good way but here is a really hackish way.

    edit: will have to post later for you appeenty my phone can't copy and paste python and have it formatted correctly.

    it is still a big hack job to do since you are actually quwrory the viewport ui element.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    string $cameras[] = `ls -cameras`;
    for ($camera in $cameras) {
        int $isRenderable = `getAttr ($camera+".renderable")`;
        if ($isRenderable == 1){
            //Do whatever you want here         
            print $camera;
        }
    }
    

    Damn rusty as hell in MEL now haha. Basically each camera has a renderable flag.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    @haiddasalami is there anything similar for the camera used as the viewport camera?

    currently i have to do this hack job
    import maya.cmds as cmds
    
    
    def getCurrentCamera():
        '''
        gets the current maya viewport camera
        '''
        pan = cmds.getPanel(wf=True)
        cam = cmds.modelPanel(pan, q=True, camera=True)
        return cam
    
    
    def setCurrentCamera(cam):
        '''
        Sets the curreny maya viewport camera
        '''
        vpPanel = cmds.getPanel(wf=True)
        cmds.lookThru(vpPanel, cam)
    

    which only works if the mouse is above the viewport
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    Yeah that's pretty much the only way I know and annoying too :P Maybe you can see if you can query the hudnames.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    Yeah that's pretty much the only way I know and annoying too :P Maybe you can see if you can query the hudnames.

    ah your talking about where it says the camera name in the bottom middle of hte hud?

    ya guess i could figure out what section of the hud that is in and query for the contents.

    Thanks

    EDIT:

    @haiddasalami that may not be possible the maya.cmds.headsUpDisplay() command requires the hud objects name as a argument, and i don't know anyways to figure out what the default hud object is named.
  • haiddasalami
    Options
    Offline / Send Message
    haiddasalami polycounter lvl 14
    global proc string findNewCurrentModelView() {
    
    	global string $gMainPane;
    
    	string $mainPaneCtls[];
    	string $visPanels[];
    	string $panelName;
    	string $panelCtl, $edCtl;
    	string $modelEd;
    	int    $nArr;
    	int	   $i;
    	string $newViewFound;
    	string $newView;
    
    	//
    	//  First try to find something in the main pane.
    	//
    	if ($gMainPane != "") {
    		
    
    		$mainPaneCtls = `paneLayout -q -ca $gMainPane`;
    		$nArr = size($mainPaneCtls);
    		for ($i = 0; $i < $nArr; $i++) {
    			$panelName = `getPanel -containing $mainPaneCtls[$i]`;
    			if ("" != $panelName) {
    				if ("modelPanel" == `getPanel -to $panelName`) {
    					if (!`control -q -io $mainPaneCtls[$i]`) {
    						$modelEd = `modelPanel -q -modelEditor $panelName`;
    						if ("" != $modelEd) {
    							//
    							//	If this view is already active, let's
    							//	continue to use it.
    							//
    							if (`modelEditor -q -activeView $modelEd`)
    							{
    								$newView = $modelEd;
    								string $camera = `modelPanel -q -camera $newView`;
    								print $camera;
    								break;
    							}
    						}
    					}
    				}
    			}
    		}
    	}
    	return $newView;
    }
    
    findNewCurrentModelView();
    

    Did some hunting and found the findCurrentView script. This doesnt require the mouse to be under as its using the active View flag. May be of some use. Sorry for the hijack Toast ! Also changed it from returning an int to a string(the model editor) Sorry didnt bother converting it to Python though should be simple. Only thing might be getting the mainPanel.
  • passerby
    Options
    Offline / Send Message
    passerby polycounter lvl 12
    ya think i will stick to my method when i know the user will have the viewport as the active pane.

    since to accomplish that via python mel.eval() needs to be used to get the global variable that is needed.

    my script that im using this with is a zbrush style viewport snap, so it actually is a safe assumption that it is being activated while the cursor is on the viewport.
  • Toast
    Options
    Offline / Send Message
    Toast polycounter lvl 11
    Sorry guys, I don't get email from this board and long weekend here, but thanks for the pointers, will dive into some of these scripts.

    Really appreciate the help! :)
Sign In or Register to comment.