PDA

View Full Version : Constrain to different selected objects


nottoshabi
03-30-2008, 02:23 AM
I want to set a parent constrain to different selected objects. So what I need to do is set up a switch that would take into consideration the first object then parent constrain the first object to the next selected objects. Up to 5 objects. This is what I got so far and its not working any help would be apreciated


// Create the selection

proc makeDaConstrain ()

{

string $select[] = `ls -sl -l`;
group -em -n "Stationarry";
string $select;
do {
parentConstrain -w .3 $select[1] $select[0];
parentConstrain -w .7 Statioanrry $select[1];

parentConstrain -w .3 $select[2] $select[0];
parentConstrain -w .7 Statioanrry $select[2];


parentConstrain -w .3 $select[3] $select[0];
parentConstrain -w .7 Statioanrry $select[3];
}
while ($select);


}

makeDaConstrain;

greatPumpkin
03-30-2008, 11:06 AM
try this: ( due to laziness i didn't add the weight flags back in to the parentConstraint command) this code should parent constrain an infinite number of objects to the first selected object. Not sure why you were creating a 'stationary' group null?


// Create the selection

proc makeDaConstrain ()

{

string $select[] = `ls -sl -l`;


for($i = 1;$i < `size $select`;$i++)
{
parentConstraint $select[0] $select[$i];
}

}

makeDaConstrain;

nottoshabi
03-31-2008, 06:51 AM
GreatPumking, that was much easier then what I had in mind. Ok, now another question. How can I make the weight be diveded by the number of selections? So that the first selection and the last selection do not have the same weight on the constrain. So they dont all fallow with the same weight they will have a fall off. I was creating the Stationary so that they have something to be constrain to besidse the first selection to create the fall off fallow.

greatPumpkin
03-31-2008, 05:02 PM
do you want fries with that? hehe, just kidding- this should do it, basically taking the amount of objects selected and dividing it by 1.0 to get a percentage value to pass to the constraint weights.



proc makeDaConstrain ()
{
string $select[] = `ls -sl -l`;

// the weight value needs to be delcared outside the loop since it's being updated to
// allow different values per object.
float $weight = 1.0 / `size $select`;
float $inc = $weight;

string $null = `group -em -n "stationary"`;

for($i = 1;$i < `size $select`;$i++)
{
string $con[] = `parentConstraint $select[0] $null $select[$i]`;

// get the weight attributes frmo the constraint
string $attr[] = `listAttr -k -ud $con[0]`;

// set the first weight attribute to our current value, and set the reverse value
// on the 'stationary' part of the constraint.
setAttr ($con[0] + "." + $attr[0]) $weight;
setAttr ($con[0] + "." + $attr[1]) (1.0 - $weight);

// this line increments the weight float value each time to get the
// varied falloff behavior
$weight += $inc;
}

}

makeDaConstrain;

nottoshabi
04-01-2008, 01:06 AM
Ohhh wow dude. Thanks, and no I dont want fries with that. Is allready to much. You should of just wrote the division line. What does the size comand do?

greatPumpkin
04-01-2008, 05:26 AM
hehe, no prob- the size command returns the 'size' of something, so for an array, it will return the number of items in the array, and for a string, it would return the number of characters in the string.

CGTalk Moderation
04-01-2008, 05:26 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.