PDA

View Full Version : Select All Children Without Parent and Vice Versa


gotanidea
11-30-2011, 06:00 AM
What is the MEL script for:
- Selecting all children without its parent?
- Selecting the parent without its children?

berniebernie
11-30-2011, 10:30 AM
this seems to do the trick:


//children
$o = `ls -sl -o`;
$ch = `listRelatives -c $o`;
select -r $ch;

//parent
$o = `ls -sl -o`;
select -r `firstParentOf($o[0])`;


maybesomeone has a better solution.

gotanidea
11-30-2011, 11:05 AM
this seems to do the trick:


//children
$o = `ls -sl -o`;
$ch = `listRelatives -c $o`;
select -r $ch;

//parent
$o = `ls -sl -o`;
select -r `firstParentOf($o[0])`;


maybesomeone has a better solution.

Doesn' work... The "children" script returns error message if some of the children have identical name... And the "parent" script doesn't exclude the children in the selection...

Thanks anyway bernie :)

NaughtyNathan
11-30-2011, 12:31 PM
to avoid clashing names use the listRelatives -f flag, and you CANNOT select parents without their children being selected in Maya. You can select a parent's SHAPE node and the children won't be selected, but these are not really children in this context as the hierarchy is being circumvented (you're not really selecting the parent).

:nathaN

gotanidea
11-30-2011, 01:03 PM
to avoid clashing names use the listRelatives -f flag, and you CANNOT select parents without their children being selected in Maya. You can select a parent's SHAPE node and the children won't be selected, but these are not really children in this context as the hierarchy is being circumvented (you're not really selecting the parent).

:nathaN

Thanks.

Suppose I select the parent first. Then I want to select the children and deselect the parent. Is there a way to do this with MEL script?

NaughtyNathan
11-30-2011, 01:25 PM
the MEL command:select -hi;will select the complete hierarchy under the current selection. if you then want to deselect the parent you just need to do:select -d $origSelection;to deselect the original selection (assuming you already grabbed it with this name).
However, working with selections like this isn't a very sophisticated way of managing DAG nodes and hierarchies. if you only want to know this for basic hotkeys or buttons that's fine, but if you are trying to write a script to work on parts of a hierarchy you should ditch select altogether and learn how to use the ls and listRelatives commmands properly so you can do this stuff right.
:nathaN

gotanidea
12-03-2011, 04:39 AM
the MEL command:select -hi;will select the complete hierarchy under the current selection. if you then want to deselect the parent you just need to do:select -d $origSelection;to deselect the original selection (assuming you already grabbed it with this name).
However, working with selections like this isn't a very sophisticated way of managing DAG nodes and hierarchies. if you only want to know this for basic hotkeys or buttons that's fine, but if you are trying to write a script to work on parts of a hierarchy you should ditch select altogether and learn how to use the ls and listRelatives commmands properly so you can do this stuff right.
:nathaN

I'll try it. Thanks for your explanation Nathan :)

CGTalk Moderation
12-03-2011, 04:39 AM
This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.