Expand / Collapse All Selected in Outliner

Expand / Collapse All Selected in Outliner

andymc4997
Advocate Advocate
1,986 Views
4 Replies
Message 1 of 5

Expand / Collapse All Selected in Outliner

andymc4997
Advocate
Advocate

Hi everyone, 

 

I came across this script to expand all selected items in the Outliner, but it's not a toggle to then collapse only those selected items. I'm sure this would be an easy MEL, but I'm certainly no programmer. Can someone advise?

 

Thanks!

 

select -hi;fitPanel -selected;

0 Likes
1,987 Views
4 Replies
Replies (4)
Message 2 of 5

mcw0
Advisor
Advisor

outlinerEditor -e -eas false outlinerPanel1;

0 Likes
Message 3 of 5

andymc4997
Advocate
Advocate

Hi @mcw0 , thanks for your reply. 

 

Your code only works to collapse the hierarchy for me, not toggle it back open. How can I make it work in tandem with my existing code to create a toggle?

0 Likes
Message 4 of 5

mcw0
Advisor
Advisor

To make it able to toggle, you'd have to query the expanded state of the outliner.  From what I see in the docs, that is not possible.  So to get around that, create a global variable for the expanded state.  This could get messy real fast.  You'd also have to keep track of which hierarchies are in play.  I feel it's doable.  Just have to give it some thought.  Good luck.

0 Likes
Message 5 of 5

mcw0
Advisor
Advisor

I just reread your original post where you state you are not a programmer.  Since the process to expand and compress in the outliner requires a mouse click and the shift key.  And a custom tool to do this will only require a mouse click.  I'm failing to see much benefit from such a tool except in the case where one commonly needs to expand/compress a number of selected hierarchies.

 

In any case, I can try to give you some ideas here.  These will be untested...off the top of my head...stuff.

In your "userSetup.mel", add the following to initialize the variable for your session of Maya.  This approach will only work with a new session of Maya.  If you open a new file in an existing session, it will not.

 

//  global variable as an array to handle multiple selections
global int $expandedState;

$expandedState = -1;

 

Now for your script.

 

global proc $expandedState;

if($expandedState < 0)

    $expandedState = 0;  //  this will initialize for your session of Maya

 

outlinerEditor -e -eas (1-$expandedState) outlinerPanel1;

$expandedState = 1-$expandedState;

 

0 Likes