March 2019: is getting relocated to, please update your bookmarks.

MEL How-To #14

Back · Previous · Next Maya

How do I get and set the ‘Show’ Options for the currently active layout panel?

First you need to get the name of the active panel and, for the purposes of twiddling ‘Show’ options, confirm that it is a modelPanel.

proc string getActiveModelPanel()
  string $activeModelPanel = "";

  // First get the panel that currently has focus
  string $panel = `getPanel -wf`;

  // Compare the panel's type to confirm it is a "modelPanel"
  if ( "modelPanel" == `getPanel -to $panel` )
    $activeModelPanel = $panel;

  return $activeModelPanel;

Note that before you perform any of the following in a script, you'd want to assert that the panel name was valid (ie. not NULL):

string $activeModelPanel = getActiveModelPanel();
if ( "" != $activeModelPanel )
  // get/set option here

The method is the same for getting and setting all options. The only difference is the name of the option being queried or assigned.

To get the status of a panel option:

int $status = `modelEditor -q -«option» $activeModelPanel;

To set the status of the panel option:

modelEditor -e -«option» «status» $activeModelPanel;

For the most part, the option in the MEL command is the same as that in the ‘Show’ menu. Some examples:

int $showCameras = `modelEditor -q -cameras $activeModelPanel;
// Result: 1 //  Showing cameras  //

int $showJoints = `modelEditor -q -joints $activeModelPanel;
// Result: 1 //  Showing joints  //

int $showPivots = `modelEditor -q -pivots $activeModelPanel;
// Result: 0 //  Not showing pivots  //

int $showGrid = `modelEditor -q -grid $activeModelPanel;
// Result: 1 //  Showing grid  //
modelEditor -e -nurbsCurves off $activeModelPanel;    // Show nurbsCurves

modelEditor -e -nurbsSurfaces on $activeModelPanel;   // Show nurbsSurfaces

modelEditor -e -polymeshes on $activeModelPanel;      // Show poly meshes

modelEditor -e -cameras off $activeModelPanel;        // Don't show cameras

When in doubt of the name of the option to use, turn on ‘Echo All Commands’ in the Script Editor and select an item in the ‘Show’ menu. The echoed command will reveal the required name for the MEL command.