一半君的总结纸

听话只听一半君

#66 How do I control the Graph Editor’s Outliner and Graph panels?

The Graph Editor is defined as a scriptedPanelType in the MEL script:

\AW\Maya3.0\scripts\startup\initScriptedPanels.mel

and created in:

\AW\Maya3.0\scripts\others\graphEditorPanel.mel

It is a pairing of an outlinerEditor and an animCurveEditor. The contents of the Graph Editor editors are controlled via selectionConnections. Here’s a rundown of how they work:

  • The outlinerEditor has for its -mainListConnection the global “graphEditorList”. A “mainListConnection” controls which items are listed in an editor.
  • The outlinerEditor has for its -selectionConnection a selectionConnection object that is created when the GraphEditor’s scriptedPanel is created. This “broadcasts” to the animCurveEditor which items have been selected in the Outliner, and the animCurveEditor alters its contents accordingly.
  • As inferred above, the animCurveEditor has for its -mainListConnection the outlinerEditor’s selectionConnection. Select an item in the outlinerEditor and «shazam!» there it is in the animCurveEditor.

So, to get and set the items selected via the Graph Editor, you need to control the items in the -selectionConnection for its Outliner. This will have the reciprocal effect of “selecting” an item in Graph Editor’s animCurveEditor, thanks to the direct relationship that exists.

Firstly, you need to know how to get at the objects in the Graph Editor:

The Graph Editor’s scriptedPanelType is “graphEditor”:

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

This is the scripted panel, not its editor(s). Now take a snoop into the “graphEditorPanel.mel” script. Note that Alias hardcodes the names of the Graph Editor’s editors with:

string $graphEd = ($whichPanel + "GraphEd");
string $outlineEd = ($whichPanel + "OutlineEd");
string $outlineConn = ($whichPanel + "FromOutliner");

From top to bottom: the animCurveEditor, the outlinerEditor and the selectionConnection used by the outlinerEditor. The $whichPanel variable will be the name of the scripted panel’s main control; e.g.

scriptedPanel -q -control graphEditor1;
// Result: graphEditor1Window|TearOffPane|graphEditor1 //

Note that this will only return a valid result when the GraphEditor is visible.

To cut to the chase, you can reasonably assume that the names will be:

      animCurveEditor: "graphEditor1GraphEd"
       outlinerEditor: "graphEditor1OutlineEd"
  selectionConnection: "graphEditor1FromOutliner"

Examples

Determine what objects are listed in the Graph Editor’s Outliner:

string $graphEditorObjects[] = `selectionConnection -q -object graphEditorList`;

Determine what objects are selected in the Graph Editor’s Outliner:

string $graphEditorSelection[] = `selectionConnection -q -object graphEditor1FromOutliner`;

You can use this to replace Maya’s global selection so the item becomes active in the Channel Box:

select $graphEditorSelection;

To clear the selection of the Graph Editor:

selectionConnection -e -clear graphEditor1FromOutliner;

To select all objects in the Graph Editor:

string $graphEditorObjects[] = `selectionConnection -q -object graphEditorList`;

for ( $object in $graphEditorObjects )
{
  selectionConnection -e -select $object graphEditor1FromOutliner;
}

To replace the contents of the Graph Editor with pSphere1 and display its .translateY channel in the animCurveEditor:

select -r pSphere1;   // Maya's global selection controls contents
                      // of Graph Editor's Outliner

selectionConnection -e -clear graphEditor1FromOutliner;
selectionConnection -e -select pSphere1.translateY graphEditor1FromOutliner;

To select items in the animCurveEditor, use the ‘selectKey’ MEL command:

// Select the sphere's .translateY channel in the graph
selectKey pSphere1_translateY;

// Clear the graph selection
selectKey -clear;

// Select key range 112 through 180 for the .translateY channel.
// Note you'll have to deduce the name for the controlling animCurve.
selectKey -add -t "112:180" pSphere1_translateY ;

Related How-To’s

06 March 2003

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 博主赞过: