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

MEL How-To #53

Back · Previous · Next Maya

How do I dock Maya's Graph Editor, HyperGraph, Render View, et al, in my own window?

The Graph Editor, Hypergraph and Render View are members of a family of "scripted panels" used within Maya. You can view a list of the Scripted Panel types by using the ‘getPanel’ command:

getPanel -allScriptedTypes;
// Result: dopeSheetPanel graphEditor hyperGraphPanel multiListerPanel renderWindowPanel //

These results are abbreviated, but you get the idea.


Creating A Tear-Off Window

If you simply want a panel to tear-off into its own window then you can use an existing MEL command that the Maya developers defined for that purpose. Its argument format is:

tearOffPanel <panelLabel> <panelType> <isScripted>;

To tear-off or open the Graph Editor in its own window:

tearOffPanel "Graph Editor" graphEditor true;

The panelType argument is derived from the getPanel list above. Since we know the Graph Editor is a Scripted Panel, the isScripted argument must be true in this case.

It's simply a matter of replacing the panelLabel and panelType for each of the panels to open:

tearOffPanel "Hypergraph" hyperGraphPanel true;

tearOffPanel "Dope Sheet" dopeSheetPanel true;

tearOffPanel "Render Window" renderWindowPanel true;
// Error: file: D:/AW/Maya3.0/scripts/startup/tearOffPanel.mel line 55:
          Only one instance of this panel type allowed: renderWindowPanel //
Whoops. That didn't work. However, a little more investigation reveals that the Render View menu command executes the following:
tearOffPanel "Render View" renderWindowPanel true;

All that's different is the label used for the window, but it does work.


Docking In A Window With Other Controls

Now what if you've got other ideas and want to dock one of these panels into your own window with other controls? Let's use the Graph Editor for the first example.

window;
  string $form = `formLayout`;

    // Add a paneLayout to hold the Graph Editor
    string $pane = `paneLayout -configuration "single"`;

      // The 'scriptedPanel' command is used here, and the type specified
      // is again taken from the results of the 'getPanel' list.
      scriptedPanel -type "graphEditor";

        // The scriptedPanel returns its own layout, so we
        // must setParent one level up before continuing...
        setParent ..;

      setParent ..;

    // Add additional controls to the window
    string $row = `rowLayout -numberOfColumns 2`;
      button -label "Select Character";
      button -label "Do something else";
      setParent ..;

    setParent ..;

  formLayout -e
    -af   $row          "left"    2
    -af   $row          "right"   2
    -af   $row          "bottom"  2
    -af   $pane         "top"     2
    -af   $pane         "left"    2
    -af   $pane         "right"   2
    -ac   $pane         "bottom"  4   $row
      $form;

showWindow;

Achieving a similar layout for the other panel types is again a matter of changing the panel type specified after the scriptedPanel command:

scriptedPanel -type "dopeSheetPanel";

scriptedPanel -type "hyperGraphPanel";

The Finicky Render View

But what about the Render View? Attempting to substitute "renderWindowPanel" into the above script will reward you with:

// Error: Only one instance of this panel type allowed: renderWindowPanel //

Maya will not allow you to create an additional scriptedPanel of type "renderWindowPanel". But there's nothing preventing you from using the one that already exists:

window;
  string $form = `formLayout`;

    // Just create the layout for now and leave it empty.
    string $pane = `paneLayout -configuration "single"`;
      setParent ..;

    string $row = `rowLayout -numberOfColumns 2`;
      button -label "Refresh Textures";
      button -label "Save Light Map";
      setParent ..;

    setParent ..;

  formLayout -e
    -af   $row          "left"    2
    -af   $row          "right"   2
    -af   $row          "bottom"  2
    -af   $pane         "top"     2
    -af   $pane         "left"    2
    -af   $pane         "right"   2
    -ac   $pane         "bottom"  4   $row
      $form;

// Find the Render View panel
string $renderViews[] = `getPanel -scriptType renderWindowPanel`;

if ( size( $renderViews ) )
{
  // Unparent the scriptedPanel from where it is currently docked
  scriptedPanel -e -unParent $renderViews[0];
  // Fill the 'hole' left in the UI from removing the Render View
  fillEmptyPanes;
}
else
// A Render View panel was not found -- create an unParented panel
{
  global int $gUseMenusInPanels;
  scriptedPanel -mbv $gUseMenusInPanels -type renderWindowPanel
                -unParent -l "Render View" renderView;
}

// Now dock the Render View into our own layout.
scriptedPanel -e -parent $pane $renderViews[0];

showWindow;

Note: If you try to use a saved Panel Configuration containing the Render View while your custom window contains the Render View then Maya will choke with an error. However, it's perfectly fine to use this script to transfer the Render View from a Panel Configuration. This just goes to show that your script will be smarter than Maya's own!


Related Tutorial

05 August 2002