PDA

View Full Version : getAttr in for loop


ForOinObjectsDoPrintName
09-13-2009, 04:38 AM
Hey guys,

I'm trying a really simple code that simply prints out the translateX values of the current selection. It works fine with a single node selected, but with multiple nodes it errors.

string $mySelection[] = `ls -sl`;

for ($myNode in $mySelection)
{
float $myVal = `getAttr $myNode.translateX`;
print $myVal;
}

The error it brings up is:
Error: Cannot convert data of type float[] to type float.

I'm experienced with maxscript, so i'm a little dumbfounded that I can't get this working. Can't seem to find a straight answer anywhere either :S. Thanks!

isoparmB
09-13-2009, 07:11 AM
Try:

string $mySelection[] = `ls -sl`;
string $myNode;

for ($myNode in $mySelection)
{
float $myVal = `getAttr ($myNode + ".translateX")`;
print $myVal;
};

ForOinObjectsDoPrintName
09-13-2009, 08:00 AM
Thanks Martin, that seems to do it :).

CGTalk Moderation
09-13-2009, 08:00 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.