PDA

View Full Version : parenting


ltethe
01-23-2009, 12:53 AM
string $selection[] = `ls -sl -type joint`;
for($each in $selection){

string $father = $each;
$child = `duplicate $father`;
parentConstraint $father $child;
}


So I'm trying to duplicate a chain of joints, and parent constrain them to the original as they're being duplicated...

The duplicates all come out... But the parenting... not so much...

Anybody care to lead a mel noob in the right direction?

Also... Um... What's the difference between:

$string and $string[]?

isoparmB
01-25-2009, 02:06 PM
The [] brackets indicate an array variable, or a variable that can store more than one input. Some types of maya operations such as duplicate, which can return more than one result, should use this type of variable (in this case a string array).

You can access each element of an array by using an integer in the brackets, arrays are 0 based indices so the first object is referred to at 0, next is 1, then 2, and so forth (eg. $child[2] - refers to the third object in an array called $child)

Your $child should be

string $child[] = `duplicate $father`;
parentConstraint $father $child[0];

since the duplicate command can return multiple results (even if you know you only have one result).

As an afterthought, you said that you're duplicating a joint chain, and reparenting all the duplicates to the original. You might want to delete the children of your duplicate before proceeding, otherwise you'll end up with a lot of redundant unused children. Maybe something like this:

string $child[] = `duplicate $father`;

string $reltives[] = `listRelatives -children $child[0]`;
delete $relatives;
parentConstraint $father $child[0];


could help.

ltethe
01-26-2009, 08:23 AM
BLAM!

You the man isoparmB! That worked and greatly helped my comprehension.

I've been struggling with this for a week now, trying to piece my noobish knowledge of mel to create this script... This sucker is ugly, and dirty, but dammit, it works!

Damn if that sense of accomplishment doesn't feel good.

global proc addTSL(){

//select the entire hierarchy
select -hi;

// create list of selected joints
string $selectionSet[] = `ls -sl -type joint`;
string $childSet[] = `duplicate -rc $selectionSet`;

for($i=0; $i<size($selectionSet); $i++){

for($each in $selectionSet){

parentConstraint $selectionSet[$i] $childSet[$i];
}
}
}

The parenting wasn't working forever... Took me a while to realize that for whatever reason, it wasn't cycling through the joints appropriately, so I created a bean counter attribute, and blam, it all clicked.

I gotta go celebrate. Scripting has to be one of the most challenging things I've tackled in my life... My mind just isn't wired real good for this... I need beers.

isoparmB
01-26-2009, 09:06 AM
Heheh. Glad it's working out for you.

CGTalk Moderation
01-26-2009, 09:06 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.