MEL How-To #42 | ||
| ||
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.
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 " Unfortunately, there is no mechanism in MEL to easily backtrack from an
existing panel to its parent window -- the ‘ 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 -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'sWednesday, January 10, 2001 | ||
Copyright ©2005 by Bryan Ewert, maya@ewertb.com Maya is a Registered Trademark of Alias |