PDA

View Full Version : any best practise for gettin a TransX in an expression


Phlok
10-02-2009, 12:55 PM
Hi,

in my expression, I want to translate some spheres. So I first put them all into an array and in a for- loop there are some operations done.

Unfortunately, I always get syntax errors:



string $spheres[] = `ls -type geometryShape`;
int $offset = frame - $frmStart;
for($i = 0; $i <= $offset; $i++)
{
float $posY = $spheres[$i].translateY;
if($posY < $yMax)
{
$spheres[$i].translateY = $posY + smoothstep($yStart, $yMax, $posY);
}
else
{
$spheres[$i].translateY = $posY - smoothstep($yStart, $yMax, $posY);
if($spheres[$i].translateY < 0)
{
$spheres[$i].translateY == 0;
}
}
}

Maya don't like this $spheres[$i].translateYand I really do not see, why that is so.

Coming from an object oriented programming language, it feels really disturbing not to be able to just have an array of sphere objects but of strings identifiying those sphere objects.

So now I want to call the translateX variable of the spheres via that array but all I get is a syntax error. So how do I do that correctly with MEL?

benio33
10-02-2009, 01:43 PM
translateY is an attribute. You set and get values of attributes using getAttr and setAttr methods.

setAttr ($spheres[$i] + ".translateY") $someValue;

is the proper syntax

Phlok
10-02-2009, 03:37 PM
Thanks for your help.

Albeit, setAttr and getAttr are not to be used in expressions this parenthesis thing was what I was looking for.

I wish AD really integrates Python in Maya 2011 (...right now it is a bad joke, as there is still no form of object orientation in Maya Python. It's MEL with a different syntax and the ability to link external libraries).

benio33
10-02-2009, 04:17 PM
"this parenthesis thing" :) is basically parsing string, that's all. Python is well integrated into Maya, this is Maya itself who doesn't give you direct access into its variables. Even Maya API itself doesn't give you direct controll over its attributes. Therefore I doubt even Maya 2022 (unless the World ends in 2012 :) ) will allow object.translateX = 10 form of assignment ... or maybe I exaggerate a bit ... anyways - using setAttr and getAttr is perfect in expressions, unless you mean runtime expressions then yes, they don't make sense then.

efecto
10-03-2009, 10:52 PM
$spheres[$i].translateY = 0;

instead of
$spheres[$i].translateY == 0;

???

CGTalk Moderation
10-03-2009, 10:52 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.