March 2019: ewertb.soundlinker.com is getting relocated to ewertb.mayasound.com, please update your bookmarks.

MEL How-To #42

Back · Previous · Next Maya

How do I find/close Maya's editor windows -- the Dope Sheet and Graph Editor, for example?

Maya editor windows are primarily based on panels (an editor window is typically a torn-off panel). You can query panel information using the MEL command getPanel.

There are several ways to determine if the Graph Editor window/panel is currently displayed.

  1. You could do a string-match to find the Graph Editor panel(s).

    getPanel -visiblePanels;
    // Result: modelPanel4 graphEditor1 //
    

    Scan the returned array for the string "graphEditor", likely using the ‘gmatch’ MEL command. Those that match stand a good chance of representing a Graph Editor panel.

  2. Typically the Graph Editor has the label "Graph Editor".

    getPanel -withLabel "Graph Editor";
    // Result: graphEditor1 //
    

    The panel returned in this query is likely a Graph Editor.

  3. Query all existing panels of scripted type "graphEditor".

    getPanel -scriptType graphEditor;
    // Result: graphEditor1 //
    

    As above, this is likely a Graph Editor.

As implied here, the Graph Editor is a scripted panel type. Its behavior is controlled (at least partially) through MEL support scripts.

Closing the Graph Editor window is not as simple as deleting "graphEditor1." This doesn't kill the window but rather deletes the panel within the window.

Unfortunately, there is no mechanism in MEL to easily backtrack from an existing panel to its parent window -- the ‘−parent’ flag for the ‘scriptedPanel’ command does not offer a Query mode.

It is sometimes possible to query the "control" for the scriptedPanel and tokenize the UI path to extract the window portion:

string $graphEditor[] = `getPanel -scriptType graphEditor`;
for ( $editor in $graphEditor )
{
  string $tokens[];
  string $control = `scriptedPanel -q -ctl $editor`;

  if ( $control != "" )
  {
    if ( 0 < `tokenize $control "|" $tokens` )
    {
      print ( "Window for Graph Editor: " + $tokens[0] + "\n" );
    }
  }
  else
    print ( "Could not determine Window for Graph Editor.\n" );
}

// Result: Window for Graph Editor: graphEditor1Window //

Note: Heed the documentation warnings -- it is possible for the control to be NULL. Make sure you check for this.

As the above suggests, it is somewhat a standard practice within Maya for a panel's parent window to simply be the name of the panel appended with the string "Window". If you want to make this assumption, you could do this:

string $graphEditor[] = `getPanel -scriptType graphEditor`;
for ( $editor in $graphEditor )
{
  string $graphEditorWindow = ( $editor + "Window" );

  if ( `window -exists $graphEditorWindow` )
    print ( "Window for Graph Editor: " + $graphEditorWindow + "\n" );
  else
    print ( "Could not determine Window for Graph Editor.\n" );
}

// Result: Window for Graph Editor: graphEditor1Window //

Now that you've found the window for the Graph Editor you can "close" it using the ‘deleteUI’ command:

deleteUI -window graphEditor1Window;

Note: If the editor panel is currently docked, your query will identify the main Maya window:

// Result: Window for Graph Editor: MayaWindow //

It's likely not a good idea to delete this window. The user may get upset.

Most of the above should work for all UI panels, and not just the Graph Editor.

// Query derived from panel's control
string $dopeSheetPanels[] = `getPanel -scriptType dopeSheetPanel`;
// Result: dopeSheetPanel1 //

string $dopeSheet = $dopeSheetPanels[0];

string $control = `scriptedPanel -q -ctl $dopeSheet`;
// Result: dopeSheetPanel1Window|TearOffPane|dopeSheetPanel1 //

if ( $control != "" )
{
  string $tokens[];
  if ( 0 < `tokenize $control "|" $tokens` )
  {
    print ( "Window for Dope Sheet: " + $tokens[0] + "\n" );
  }
}
else
  print ( "Could not derive Dope Sheet Window from control.\n" );

// Result: Window for Graph Editor: dopeSheetPanel1Window //

// Query assuming name includes "Window" string
string $dopeSheetWindow = ( $dopeSheet + "Window" );

if ( `window -exists $dopeSheetWindow` )
  print ( "Window for Dope Sheet: " + $dopeSheetWindow + "\n" );
else
  print ( "Could not find Dope Sheet Window by name.\n" );

// Result: Window for Dope Sheet: dopeSheetPanel1Window //

Related How-To's

Wednesday, January 10, 2001