PDA

View Full Version : toggle questions


eblondin
06-02-2006, 08:17 PM
two questions

how to toggle high quality rendering mode

toggleHWRendererModelPanel 0 modelPanel1; is off
toggleHWRendererModelPanel 1 modelPanel1; is on

and how to toggle the persp/outliner view

setNamedPanelLayout "Persp/Outliner"; updateToolbox(); opens the outliner with perspective
setNamedPanelLayout "Single Perspective View"; updateToolbox(); just perspective

I know the commands for these but cant figure out how to write a tiny simple script for a hotkey to toggle these, seems simple enough though right? :)

StephG
06-03-2006, 02:03 AM
OK. Let's try this.


global proc string toggleHWRender()
{
string $panel = `getPanel -wf`;//This gets your current model panel
string $currentRenderStatus = `modelEditor -q -rnm $panel`;
switch ($currentRenderStatus)
{
case "base_OpenGL_Renderer"://if your current status is base OGL...
modelEditor -e -rnm "hwRender_OpenGL_Renderer" $panel;//...it switches to hwOGL
menuItem -e -en true hwRenderShadeOptionItem;
break;
case "hwRender_OpenGL_Renderer":if your current status is hwOGL...
modelEditor -edit -rnm "base_OpenGL_Renderer" $panel;...it switches to baseOGL
menuItem -edit -enable false hwRenderShadeOptionItem;
break;
}
$currentRenderStatus = `modelEditor -q -rnm $panel`;
return ("New HW Render Mode: " + $currentRenderStatus + "\n");/*sends new status to the command feedback line or the script editor feedback line*/
}


Now execute this and any time you type toggleHWRender; it will toggle your hw render status.

if you just want to put it into the hotkey editor and have it work there:

string $panel = `getPanel -wf`;
string $currentRenderStatus = `modelEditor -q -rnm $panel`;
switch ($currentRenderStatus)
{
case "base_OpenGL_Renderer":
modelEditor -e -rnm "hwRender_OpenGL_Renderer" $panel;
menuItem -e -en true hwRenderShadeOptionItem;
break;
case "hwRender_OpenGL_Renderer":
modelEditor -edit -rnm "base_OpenGL_Renderer" $panel;
menuItem -edit -enable false hwRenderShadeOptionItem;
break;
}
$currentRenderStatus = `modelEditor -q -rnm $panel`;
print ("New HW Render Mode: " + $currentRenderStatus + "\n");


Incidentally, the command "toggleHWRendererModelPanel" is one of those "others" scripts that aren't documented. You can find it and take it apart by typing:
whatIs toggleHWRendererModelPanel;
in the command line.

Don't have the time right now to do the perspective/outliner switch.

eblondin
06-03-2006, 05:32 AM
double post edit

eblondin
06-03-2006, 05:35 AM
Whoa, thank you so much Steph I really appreciate you taking the time to help me out. By the way I am a big fan of your work :). I am still learning MEL but hey if you ever have a zbrush question let me know and perhaps I can help you out.

StephG
06-03-2006, 10:25 PM
I appreciate the thanks. I wasn't gonna help people with code after I came up with a solution for someone else and they never posted acknowledgment or thanks, even after I PMed them.

BTW, I didn't really know how to do this before. But I was curious enough to try and figure it out. Best way to learn is to use the "whatIs" command if something's not in the reference docs, and then examine the entrails (take it apart and figure it out).

edit: Oh wait, that's what you wanted in the first place. Well, you'll have to wait, I guess ;) Well, actually if you just want the stock layout with persp, that's easy enough. Later today.

I might have to do one for myself that switches between single window and two windows with an outliner and current view instead of the standard "persp/Outliner". But it's too hot to take apart "setNamedPanelLayout" and figure it out right now ;)

BTW, you can use "if" statements instead of the switch/case statements if you want.

Here's your perspective/outliner switch:


global proc string sg_switchBetweenOutPers()
{
string $panel = `getPanel -wf`;
string $panelTO = `getPanel -to $panel`;
switch ($panelTO)
{
case "outlinerPanel":
lookThroughModelPanel persp $panel;
print "works\n";
break;
case "modelPanel":
if (!`panel -ex outlinerPanelA`)//if the panel doesn't exist, create it
outlinerPanel -rp $panel outlinerPanelA;
if (`panel -ex outlinerPanelA`)//if the panel does exist, edit it
outlinerPanel -e -rp $panel outlinerPanelA;
break;
}
$panel = `getPanel -wf`;
$panelTO = `getPanel -to $panel`;
return ("Current Panel: " + $panel + "\n");
}


Or if you want to run it in a hotkey:

string $panel = `getPanel -wf`;
string $panelTO = `getPanel -to $panel`;
switch ($panelTO)
{
case "outlinerPanel":
lookThroughModelPanel persp $panel;
print "works\n";
break;
case "modelPanel":
if (!`panel -ex outlinerPanelA`)
outlinerPanel -rp $panel outlinerPanelA;
if (`panel -ex outlinerPanelA`)
outlinerPanel -e -rp $panel outlinerPanelA;
break;
}
$panel = `getPanel -wf`;
$panelTO = `getPanel -to $panel`;
print ("Current Panel: " + $panel + "\n");/*only difference between the two is the print command*/

StephG
06-04-2006, 01:58 AM
OK, Take 2 here. It's hack, but it works consistently with all the tests I came up with. It seems to work the way I want it to.

This will switch between any single or selected model window and the "Persp/Outliner" configuration. With the advantage that it'll set the view at whatever you were viewing before after the switch (front, perspective, etc).

Also, if you happen to have a 4-view up before the switch, it'll first switch to a single view of whatever camera you had up in the last selected modelPanel.

You can save it out as a script, run it as a hot key or whatever.


global proc sg_switchOutliner()
{
string $currentView = `lookThru -q`;
string $currentPanels[] = `getPanel -vis`;
string $modelPanel;
int $numberOfPanels = `size($currentPanels)`;
for ($cp in $currentPanels)
{
if (`gmatch $cp "*modelPanel*"`)$modelPanel = $cp ;
}
switch ($numberOfPanels)
{
case 1:
setNamedPanelLayout "Persp/Outliner";// updateToolbox();
break;
case 2:
setNamedPanelLayout "Single Perspective View"; //updateToolbox();
break;
default:
setNamedPanelLayout "Single Perspective View"; //updateToolbox();
break;
}
lookThroughModelPanel $currentView $modelPanel;
}
sg_switchOutliner;

eblondin
06-04-2006, 05:23 AM
BOOYAH!

You are the man Steph! Works like a gem!

Thank you again for all your time and effort into this, I do really appreciate it.

Also thanks for the info on whatIs command to get more info on a specific command. That is a big help as well!

Big props!

StephG
06-04-2006, 09:24 PM
BOOYAH!

You are the man Steph! Works like a gem!

Thank you again for all your time and effort into this, I do really appreciate it.

Also thanks for the info on whatIs command to get more info on a specific command. That is a big help as well!

Big props!

De nada, bro. I'll probably use it a lot meself, and attach it to the "1" key on the keypad, where I have all my camera keys. 5 for "top", 2 for "front", 6 for "side", I add a "Left" and "Back", which are 4 and 8 respectively, 7 for perspective. All kind of "Animation Master" holdovers that I find handy.

The script for the "Left" and "Back" camera creation is:

global proc addCams()
{
string $camera[] = `camera -n Left -hc "viewSet -s %camera"`;
hide;
select -cl;
rename $camera[0] "Left";
setAttr "Left.rotateY" -90;
setAttr "Left.tx" -100;
setAttr "Left.farClipPlane" 10000;
setAttr "LeftShape.orthographic" 1;

string $camera[] = `camera -n Back -hc "viewSet -s %camera"`;
hide;
select -cl;
rename $camera[0] "Back";
setAttr "Back.rotateY" 180;
setAttr "Back.tx" 0;
setAttr "Back.tz" -100;
setAttr "Back.farClipPlane" 10000;
setAttr "BackShape.orthographic" 1;
}
addCams;


I keep that one as a shelf button and put it in all character files I work on. An example of the camera codes I use for the hotkeys is:


string $panel = `getPanel -wf`;
lookThroughModelPanel top $panel;


Why the hell Maya doesn't come standard with a left side, back and bottom camera I don't know. I used to use a "bottom" camera a lot when I modeled.

I've had this same "keypad" camera arrangement on Softimage and Max as well. I'm kind of evangelizing the idea, if you can't tell ;)

eblondin
06-04-2006, 10:17 PM
Yeah I am all about hotkeys to speed up workflow, I can hit a button on a keyboard 4 to 10 times as fast as I can move my mouse and find it in some menu even if it is on a shelf.

And I think I am the same as you with trying to keep hotkeys between different programs the same, I use max and maya a lot so I try to keep them as similar as possible.

My favorite kind of hotkeys are the ones that toggle something though. Because you get two functions in one key, very efficient!

I have over 60 personal hotkeys in maya that really, really help increase productivity.

here are a few of my personal favorite that I use a lot to help with all the different editors in maya

toggles tear off hypergraph
if ( `window -exists hyperGraphPanel1Window` )
deleteUI -window hyperGraphPanel1Window;
else
tearOffPanel "Hypergraph" "hyperGraphPanel" true;
toggles tear off uv texture editor
if ( `window -exists polyTexturePlacementPanel1Window` )
deleteUI -window polyTexturePlacementPanel1Window;
else
tearOffPanel "UV Texture Editor" "polyTexturePlacementPanel" true;
toggles tear off outliner
if ( `window -exists outlinerPanel1Window` )
deleteUI -window outlinerPanel1Window;
else
tearOffPanel "Outliner" "outlinerPanel" false;
toggles tear off graph editor
if ( `window -exists graphEditor1Window` )
deleteUI -window graphEditor1Window;
else
tearOffPanel "Graph Editor" "graphEditorPanel" true;
toggels tear off component editor
if ( `window -exists componentEditorPanel1Window` )
deleteUI -window componentEditorPanel1Window;
else
tearOffPanel "Component Editor" "componentEditorPanel" true;
toggle tear off hypershapde
if ( `window -exists hyperShadePanel1Window` )
deleteUI -window hyperShadePanel1Window;
else
tearOffPanel "Hypershade" "hyperShadePanel" true;

and with your latest script

I can replace the Case 1: with the name of another panel like the

setNamedPanelLayout "Persp/Graph"; updateToolbox(); or

setNamedPanelLayout "Hypershade/Persp"; updateToolbox();

and I can now toggle all of those with the perspective view! Super sweet man :)

StephG
06-05-2006, 05:18 AM
Way cool and yes indeed. Once you got one thing working, it always leads to some other way you can use it.

Glad this has opened up some new stuff for y'all ;)

BTW, I'm not sure you even need the "updateToolbox" command. Seems to work for me without it.

eblondin
06-05-2006, 10:16 PM
Yeah you’re right about that last code line i was just copying it from the script editor and pasting.

One thing I noticed about the toggle outliner/persp code you wrote, it doesn’t work if there is another window open like the hypershade or hypergraph. Any thoughts as to why?

StephG
06-06-2006, 03:32 AM
I knew it couldn't be that easy. I toldja it was hack ;)

Try this:


global proc sg_switchOutliner()
{
string $currentView = `lookThru -q`;
string $currentPanels[] = `getPanel -vis`;
string $modelPanel;
int $outPanel = 0;
for ($cp in $currentPanels)
{
if (`getPanel -to $cp` == "modelPanel")$modelPanel = $cp ;
if (`getPanel -to $cp` == "outlinerPanel")
{
$outPanel = 1;
if (`window -ex outlinerPanel1Window`)
{
deleteUI outlinerPanel1Window;
$outPanel = 0;
} } }
switch ($outPanel)
{
case 0:
setNamedPanelLayout "Persp/Outliner";
break;
case 1:
if (`window -ex outlinerPanel1Window`)deleteUI outlinerPanel1Window;
setNamedPanelLayout "Single Perspective View";
break;
default:
setNamedPanelLayout "Single Perspective View";
break;
}
lookThroughModelPanel $currentView $modelPanel;
}
sg_switchOutliner;


That will delete the outliner window if you have it open and open the outliner in a panel.

If you want to go straight from the outliner window to deleting it and just have the last viewed model window open:


global proc sg_switchOutliner()
{
string $currentView = `lookThru -q`;
string $currentPanels[] = `getPanel -vis`;
string $modelPanel;
int $outPanel = 0;
for ($cp in $currentPanels)
{
if (`getPanel -to $cp` == "modelPanel")$modelPanel = $cp ;
if (`getPanel -to $cp` == "outlinerPanel")
{
$outPanel = 1;
} }
switch ($outPanel)
{
case 0:
setNamedPanelLayout "Persp/Outliner";
break;
case 1:
if (`window -ex outlinerPanel1Window`)deleteUI outlinerPanel1Window;
setNamedPanelLayout "Single Perspective View";
break;
default:
setNamedPanelLayout "Single Perspective View";
break;
}
lookThroughModelPanel $currentView $modelPanel;
}
sg_switchOutliner;


...and if you want some fancy thing with a 4 view and hypershade, graph editor, etc open in 3 out of 4 panels...well, you'll have to do it yourself. But the relevant command to find out what the names of the open windows are to delete them is:
lsUI -wnd;

CGTalk Moderation
06-06-2006, 03:32 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.