MEL command to set zoom

MEL command to set zoom

EkDoreo
Enthusiast Enthusiast
2,217 Views
11 Replies
Message 1 of 12

MEL command to set zoom

EkDoreo
Enthusiast
Enthusiast

Hey, Does anyone know how to use MEL to zoom an active viewport? I have tried following various avenues but my programming abilities are next to non. I think panZoom should be able to do it but I can't get it to work. I would like to be able to reliably return to a known zoom; something I can't do with the analog zoom with mouse. Panning about without changing the zoom, in fear of loosing  the zoom position, can be a real tiring exercise.

 

-Thanks in advance for any help. Cheers

0 Likes
Accepted solutions (1)
2,218 Views
11 Replies
Replies (11)
Message 2 of 12

rajasekaransurjen
Collaborator
Collaborator

Hi,

Try This....

window;
rowColumnLayout ;
string $perspCameras[] = `listCameras -p`;
text -l "Select Camera";
textScrollList -allowMultiSelection false myCameraObj;
for($i=0;$i<size($perspCameras);$i++)
{
    textScrollList -e -append $perspCameras[$i] myCameraObj;
}
button -l "ZOOM IN" -command "rsZoomIn";
button -l "ZOOM OUT" -command "rsZoomOut";
showWindow;
global proc rsZoomIn()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    float $rsCurVal = `getAttr ($rsSlCamera[0]+".translateZ")`; 
    setAttr ($rsSlCamera[0]+".translateZ") ($rsCurVal-0.5);
}
global proc rsZoomOut()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    float $rsCurVal = `getAttr ($rsSlCamera[0]+".translateZ")`; 
    setAttr ($rsSlCamera[0]+".translateZ") ($rsCurVal+0.5);
}
0 Likes
Message 3 of 12

EkDoreo
Enthusiast
Enthusiast

Thanks for the time.

 

Effects as I see them. Only "persp" camera is in the list. Clicking the zoom in button only shifts the object down and is reflected in its translation value. Reverse for the Zoom out button. I noticed you have .translateZ in the code a few times... I like your windowed approach. Would make it easier to use than I expected.

 

-Cheers,

 

* Amended

0 Likes
Message 4 of 12

EkDoreo
Enthusiast
Enthusiast

Strange. I created a new project and it stopped moving the object. but would still only effect the perspective camera by shifting the camera up and down. I see I just noticed that it appears to translate up or down any object I have selected when i run the script. Persp camera by default. Also is the only one that updates live.

 

* Amended

0 Likes
Message 5 of 12

rajasekaransurjen
Collaborator
Collaborator

if you want we can add front side top cameras too....

0 Likes
Message 6 of 12

EkDoreo
Enthusiast
Enthusiast

Hey, That would be god since most liklyto use in thise views. But no matter what I do it will only translate and not zoom.

 

I havd been previously creating a cube of the correct size. I move it. Select it. Press F to frame the cube which zooms to fit the cube. Subject to error if the interface changes. I suspect other methods might as well.

 

Cheers

0 Likes
Message 7 of 12

rajasekaransurjen
Collaborator
Collaborator

Try this....

window;
rowColumnLayout ;
string $perspCameras[] = `listCameras`;
text -l "Select Camera";
textScrollList -allowMultiSelection false myCameraObj;
for($i=0;$i<size($perspCameras);$i++)
{
    textScrollList -e -append $perspCameras[$i] myCameraObj;
}
button -l "ZOOM IN" -command "rsZoomIn";
button -l "ZOOM OUT" -command "rsZoomOut";
showWindow;
    
global proc rsZoomIn()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal-1);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".translateZ")`;
         setAttr ($rsSlCamera[0]+".translateZ") ($rsCurVal-0.5);
    }
}
global proc rsZoomOut()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal+1);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".translateZ")`;
         setAttr ($rsSlCamera[0]+".translateZ") ($rsCurVal+0.5);
    }
}

0 Likes
Message 8 of 12

rajasekaransurjen
Collaborator
Collaborator

Hi,

Try This...Skip the above one.

window;
rowColumnLayout ;
string $perspCameras[] = `listCameras`;
text -l "Select Camera";
textScrollList -allowMultiSelection false myCameraObj;
for($i=0;$i<size($perspCameras);$i++)
{
    textScrollList -e -append $perspCameras[$i] myCameraObj;
}
button -l "ZOOM IN" -command "rsZoomIn";
button -l "ZOOM OUT" -command "rsZoomOut";
showWindow;

global proc rsFram()
{
     
     viewFit -all cameraShape1;
}
    
global proc rsZoomIn()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal-1);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".overscan")`; 
         setAttr ($rsSlCamera[0]+".overscan") ($rsCurVal-0.5);
    }
}
global proc rsZoomOut()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal+1);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".overscan")`; 
         setAttr ($rsSlCamera[0]+".overscan") ($rsCurVal+0.5);
    }
}

 

0 Likes
Message 9 of 12

EkDoreo
Enthusiast
Enthusiast

Hey  Rajasekaransurjen,

Sorry about my delay in getting back to you. Work and all that. Anyway I just tried both script. Both worked as expected. Using the third script as per your wise judgement.

 

If I were to make changes:  Would it be possible to either.

(1) have a number field to enter an exact value to zoom to? Instead of incrementing. Not all views start out equal if framing a selection. Also would want it to remember the value across the session. If you are able to do this based on my grid spacing I would be able to predict the value.

(2) Or, I would be happy editing the script as needed with an easy accessible variable.

 

If not, thanks for all your efforts. Really appreciate it. This will be a valuable tool on my shelf. Should be others who can use this as well. - Brook

0 Likes
Message 10 of 12

rajasekaransurjen
Collaborator
Collaborator
Accepted solution

Hi,

Try This....

window;
rowColumnLayout ;
string $perspCameras[] = `listCameras`;
text -l "Select Camera";
textScrollList -allowMultiSelection false myCameraObj;
for($i=0;$i<size($perspCameras);$i++)
{
    textScrollList -e -append $perspCameras[$i] myCameraObj;
}
text -l "Enter Zoom Value";
string $rsFltFld = `floatField rsFltFld`;
button -l "ZOOM IN" -command "rsZoomIn";
button -l "ZOOM OUT" -command "rsZoomOut";
showWindow;

global proc rsZoomIn()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         float $rsZmVal = `floatField -q -v rsFltFld`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal-$rsZmVal);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".overscan")`; 
         float $rsZmVal = `floatField -q -v rsFltFld`;
         setAttr ($rsSlCamera[0]+".overscan") ($rsCurVal-$rsZmVal);
    }
}
global proc rsZoomOut()
{
    string $rsSlCamera[] = `textScrollList -q -si myCameraObj`;
    if($rsSlCamera[0]=="top"||$rsSlCamera[0]=="front"||$rsSlCamera[0]=="side")
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+"Shape.orthographicWidth")`;
         float $rsZmVal = `floatField -q -v rsFltFld`;
         setAttr ($rsSlCamera[0]+"Shape.orthographicWidth") ($rsCurVal+$rsZmVal);   
    }
    else
    {
         float $rsCurVal = `getAttr ($rsSlCamera[0]+".overscan")`; 
         float $rsZmVal = `floatField -q -v rsFltFld`;
         setAttr ($rsSlCamera[0]+".overscan") ($rsCurVal+$rsZmVal);
    }
}
0 Likes
Message 11 of 12

EkDoreo
Enthusiast
Enthusiast

Hey, Thanks again,

Much better. Not exactly what I suggested but is a good addition. Now I can zoom out and back in much quicker to a fixes size. Does behave weird. Is this a limitation of Maya's mel portal zoom accessibility?

 

I'm going to set this as accepted. you have done more than enough free work for me. It is awesome what you have done for me. Thanks you so much.

 

- Brook

0 Likes
Message 12 of 12

rajasekaransurjen
Collaborator
Collaborator

You are welcome.

0 Likes