Select all joints of a character with Maya MEL

2.8k views Asked by At

I wrote an MEL script in Maya. So I want to select a joint, then run the MEL script and it selects that joint and all its children. I very new to MEL, So with running the code, it throws a bunch of errors. Can you help me reduce error or better to get rid of all of them?

The Script:

string $joints[];
string $current[] = 'ls -selection';

proc selectJoints (){
    if ('searchJoints($joints)' == 0){
       $joints['size($joints)'] = $current[0];
       pickWalk -d down; 
       $current[0] = 'ls -sl';
       selectJoints();
    }
    else{
        pickWalk -d right;
        $current[0] = 'ls -sl';
        if('searchJoints($joints)' == 0){
            selectJoints();
        }
        else{
            pickWalk -d up;
            $current[0] = 'ls -sl';
            if($current[0] == $joints[0]){
                selectJoints();
            }
        }
    }
    return;
}

select ($Joints);

proc int searchJoints (string $jns[]){
    int $result = 0;
    for ($joint in $jns[]){
        if ($current[0] == $joint){
            return 1;
        }
    }
    return 0;
}
2

There are 2 answers

0
Mendel Reis On

So, I know your question is about MEL, and I am sorry for not being able to help you with that BUT i think i can help you with python and pymel.

Try this code in a Python tab in the script editor:

import pymel.core as pm

# get selected joint
selectedJoint = pm.selected()[0]

#get all children from the selected joint and puts it in a list
joints = selectedJoint.listRelatives(allDescendents = True)

#adds first selected joint to same list
joints.append(selectedJoint)

#clears selection
pm.select(clear = True)

#loop thru list of joints
for item in joints:
    #toggle selection on selected joint and all its descendents
    pm.select(item, tgl = True)  

I am not sure why to use MEL, I started directly with pymel and it seems more powerful. Could you tell me why MEL?...I think I might be missing out on something. Anyway, I think this short code does the trick. Good luck! Be aware that there are no fail safes there. so, make sure you select ONE joint to run before running the script.

0
anon On

You can simply do:

select -hi;