Hi guys
There's a piece of code i'm not sure how to write. Here's a small example of what i'm trying to achieve:
I have two objects.
They are parent constraint to each other.
I'd like to write a piece of melscript to GET the name of the Parent object and load it into a Variable, if I have the child object selected.
I'm assuming it'd be similar to writing an string array like so:
string $array[] = `ls -sl`;
for ($item in $array) {
$Parentname = `getAttr ($item+ "Parent Constraint Name")`;
}
but I don't believe the 'getAttr' is the correct command to do this.
Any ideas?
Edit: TLDR; in simpler words.
How would I query the name of the "Parent object" if i have the child selected. (within a parentConstraint relationship)
Replies
This will identify a physical parent-child relationship.
This will find connections between an actual constraint node (Parent, Scale, Aim, etc.)
string $targetAttr = $Sel[0] +"_parentConstraint1.target";
string $connections[] = `listConnections $targetAttr`;
string $connectionsCleaned[] = stringArrayRemoveDuplicates($connections);
for ( $f in $connectionsCleaned ) {
if ( $f != $con ) {
print ( $f+ " is a Parent of " + $Sel[0] + "\n" );
}
}
run this to get the name of the parentConstraint parent of your selection. its not perfect and will break if your selection has no parentConstraint applied or if you have renamed the parentconstraint, so will need some error handling in there..
Johnny, I ran into a small issue
The if statement didn't work due to $con not being declared. -I'm not sure what the intention to compare $f to $con is.. but if I print off $connectionsCleaned .. the first object in $connectionsCleaned[0] listed, is the name of the object i'm after. You sir are awesome!
If the $f != $con argument is really important, let me know...
Thanks Jonny, I owe ya a pint !
this is what i meant to post,
string $Sel[] = `ls -sl`;
string $targetAttr = $Sel[0] +"_parentConstraint1.target";
string $connections[] = `listConnections $targetAttr`;
string $connectionsCleaned[] = stringArrayRemoveDuplicates($connections);
print ( $connectionsCleaned[0] + " is a Parent of " + $Sel[0] + "\n" );
it checks your selection, adds the default naming convention for a parent constraint, then lists its connections, cleans out all the dupes, and lists the first item in the array, which will be the parent object of your selection.
hope it helps
Thanks for thinking about adding the functionality of having multiple objects selected.
What you have here returns exactly what I needed. It's compact & easy to follow
cleaned it up a bit, automated it so it should work with any type of constraint, and added a bit of error handling,
I think I understand almost everything your doing in there, except for the tokenize cmd.
I have something new to learn today Thanks again!
So he uses $con{$f1] as a way to cycle through the multiple objects selected.
Then he tokenizes( or separates the string names) using the "_" flag and throws all those names into this $buffer
Then takes the position of the first name in the buffer[0] , then compares it to the object that's currently selected then cycles , etc, and repeats through the cycle till it reaches the maximum number of objects selected..
That's how it's making sense to me this morning.
man, those For statements always scramble my brain up...