一半君的总结纸

听话只听一半君

#14 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 -«<i>option</i>» $activeModelPanel;

To set the status of the panel option:

modelEditor -e -«<i>option</i>» «<i>status</i>» $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.

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s

%d 博主赞过: