PDA

View Full Version : if-else or for-in question


rusted_nut
07-28-2003, 07:22 AM
Here is what i'm trying to do:
Select spine joints one by one, check if their Y rotateaxis' are less than 0, if so rotate 180 degrees, otherwise do nothing.

I've started with a selection array that lists their rotateAxis'

string $spineRot[] = `ls ("spine*JNT.rotateAxis")` ;
$spine = `getAttr $spineRot` ;


I'm having trouble using that info in a statement. Should I be using a if-else solution or a for-in loop and what might it look like?

Thanks for any help

nendo
07-28-2003, 08:35 AM
Hi !

here is what I would do:

string $listSpineJoints[] = `ls ("spine*JNT") `;
string $SpineJoint ;

for ($SpineJoint in $listSpineJoints)
{

float $rotation = `getAttr ($SpineJoint+".ry")`;

if ( $rotation < 0 )

{
setAttr ($SpineJoint+".ry") ($rotation+180) ;
}

}

I hope that will help you.

rusted_nut
07-28-2003, 07:41 PM
thanks for your response nendo

could someone explain to me what a for-in loop does and how it actually works

thanks

rusted_nut
07-29-2003, 07:57 AM
Here is the solution I ended up with for the problem I posted:

string $listSpineJoints[] = `ls ("spine*JNT")` ;
string $spineJoint ;
for ($spineJoint in $listSpineJoints)
{
float $rotation = `getAttr ($spineJoint + ".rotateAxisY")` ;

if ($rotation < 0)
{
select ($spineJoint + ".rotateAxis") ;
rotate -r -os 180 0 0 ;
}
}

CGTalk Moderation
01-15-2006, 06:00 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.