PDA

View Full Version : Find Constraint Targets


giantlizard
11-24-2006, 04:49 PM
Hi everybody,

I am working on a scene in which I have hundreds of objects which all have constraints with multiple targets.
I am trying to a way to find / select one of the targets of a constraint on the current object.

Example:
I have selected an object named "ball23" which has a pointConstraint named "ball23_pointConstraint1" with three targets. The weight-attributes I see in the Channel Box are named "weight0" "weight1" "weight2".
So I need a script that selects the target for "weight2" which could be "locator577" or "locator42" or whatever.

How would I do that?
Thanks a lot.

grantimus
11-24-2006, 07:34 PM
I had a similar problem a while back. The problem I ran into is that you can only query the targets of a pointConstraint with the pointConstraint command, the targets of an aimConstraint with the aimConstraint command, etc. I tried to figure out something with the listRelatives command but that didn't pan out. In the end I had to write this procedure:


global proc string[] gtGetConstraintTargets(string $objs[]){
string $returnString[];
string $relatives[];
string $targets[];

$relatives = `listRelatives($objs)`;
for ($relative in $relatives){
if(`objectType -isType "pointConstraint" $relative`){
$targets = `pointConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "aimConstraint" $relative`){
$targets = `aimConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "orientConstraint" $relative`){
$targets = `orientConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "scaleConstraint" $relative`){
$targets = `scaleConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "parentConstraint" $relative`){
$targets = `parentConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "geometryConstraint" $relative`){
$targets = `geometryConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "normalConstraint" $relative`){
$targets = `normalConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "tangentConstraint" $relative`){
$targets = `tangentConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
if(`objectType -isType "poleVectorConstraint" $relative`){
$targets = `poleVectorConstraint -q -tl $relative`;
appendStringArray($returnString,$targets,size($targets));
}
}
return($returnString);
}


There might be a less complicated approach I don't know. But it works.

So if you want to select the targets of the constraints of the selected object you would want another procedure like this:


global proc gtSelectConstraintTargets(){
string $targets[] = gtGetConstraintTargets(`ls -sl`);
select -r $targets;
}

grantimus
11-24-2006, 07:50 PM
Ok I don't know why, but the variable $targets is getting displayes as $tar gets. I've tried editing my post to fix it, but the damned thing won't work. Anyway, I've attatched the scripts as a file to avoid any confusion.

giantlizard
11-25-2006, 01:54 PM
Hi grantimus,

THANKS A LOT!
This works perfectly.

I simplified the script a little because I only have point and orient constraints in my scene.
Also I only want one specific target to be selected so I changed the selection procedure so that I can type in a number to determin which target I want to select.

Well at this point I had the same problem with posting the code here: The variable "$targets" comes out as "$tar gets" just as in grantimus' post. How can this happen? You will find the code I use in the attached file.

To be honest, I first had to find out, what to do with a global procedure...
I use a lot of simple scripts I wrote myself, but can you believe I didn't use procedures before? or even knew what to do with them?
Well, I still have a lot to learn...

For those who also don't know:
The script in the attachment has to be executed once. After that you can select the object with the mysterious targets and for example type:
gtSelectConstraintTargets 3
to get the third item in the list of targets of its constraints.

Thanks again.

grantimus
11-25-2006, 09:27 PM
Cool, I'm glad it worked for you.

CGTalk Moderation
11-25-2006, 09:27 PM
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.