MEL How-To #47

Back · Previous · Next Maya

How do I toggle between 'Hide UI Elements' and 'Show UI Elements?'

The general MEL command for this is:

setAllMainWindowComponentsVisible <true|false>;

However, this is not a toggle. Nor does it have a query mechanism to determine in what state it is currently in, or for what state it was last called. And, passing 'true' doesn't mean "make them visible" but rather "return them to their state before they were explicitly hidden."

You have a few options:

  1. Pick one of the UI elements and use its visibility to determine if you are toggling the works on or off. For example, if you want to base it on the Time Slider:

    setAllMainWindowComponentsVisible( !isTimeSliderVisible() );
    

    Or the Shelf:

    setAllMainWindowComponentsVisible( !isShelfVisible() );
    
  2. Use your own optionVar to store the last toggled state, and use its complement as the visibility:

    int $globalUIVisibilityFlag = true;
    
    if ( `optionVar -exists globalUIVisibilityFlag` )
      $globalUIVisibilityFlag = `optionVar -q globalUIVisibilityFlag`;
    
    $globalUIVisibilityFlag = !$globalUIVisibilityFlag;
    
    setAllMainWindowComponentsVisible $globalUIVisibilityFlag;
    optionVar -intValue globalUIVisibilityFlag $globalUIVisibilityFlag;
    

    However, this could prove an inconvenience. As alluded to above, the setAll...() function doesn't specifically turn the UI elements on and off. It turns them off and restores them to their last visible state. If everything is already invisible when your own script asks everything to be invisible, the setAll...() script will remember everything as invisible and you'll have to manually toggle everything back on again.

  3. Write your own hard-toggle script that specifically hides all UI elements but also specifically unhides the UI elements that you want on.


Related How-To's

Wednesday, November 29, 2000