Expression editor changes from Maya 2015 to 2018

Expression editor changes from Maya 2015 to 2018

Anonymous
Not applicable
865 Views
6 Replies
Message 1 of 7

Expression editor changes from Maya 2015 to 2018

Anonymous
Not applicable

Hi,

I am trying to evaluate a simple expression every frame inside Maya 2018, but the result is wrong.

The funny part is that the same expression is working in Maya 2015.

Here is my expression : 

vector $location = << mainControl.translateX, mainControl.translateY, mainControl.translateZ >>; 
vector $oldlocation;

if(frame == 0)
{
    $oldlocation = $location;
}

float $speed = mag($location - $oldlocation);

print($oldlocation);
print("\n");

$oldlocation = $location;

I am just trying to get the speed of  an object in movement. 

In Maya 2015, oldlocation (which I print) is changing as expected.

In Maya 2018, its always 0. It seems like declaring $oldlocation sets it to (0,0,0).

 

How am I supposed to get the speed of the object in Maya 2018 ?

0 Likes
Accepted solutions (1)
866 Views
6 Replies
Replies (6)
Message 2 of 7

mspeer
Consultant
Consultant

Hi!

 

Your re-initialize $oldlocation every time the script runs, only at frame 0 the correct value will be assigned.

0 Likes
Message 3 of 7

Anonymous
Not applicable

Thank you for your response.

How can I declare my variable $oldlocation only once, at the beginning ? 

I can't declare it in an if statment, compiler won't accept it.

I still don't know how to get the speed of my object in maya 2018.

0 Likes
Message 4 of 7

mspeer
Consultant
Consultant
Accepted solution

Hi!

Any declaration outside of the expression will work fine.

0 Likes
Message 5 of 7

Anonymous
Not applicable

Yes this I working!

So I added a new hidden attribute to my object, I hope this is what you meant..

Thank you so much!

0 Likes
Message 6 of 7

mspeer
Consultant
Consultant

Hi!

Yes, that's one possible solution.

0 Likes
Message 7 of 7

stephenhewett3d
Observer
Observer

Hi!

I believe I'm having a similar issue with the expression editor except my issue involves getting the frame and using it as an expression of time, I know this syntax works because I've seen it in earlier versions of maya

 

float $transx;
float $mult;

$transx = go2.tx - ('getAttr -t (frame -3) go2.tx');
if ($transx > .1) $mult = go1.drive;
else #mult = go1.drive * 1.3;

go2.tx = ($mult * ('getAttr -t (frame -3) go2.tx'))+3; 

or preferably

 

go2.tx = 'getAttr -t (frame-(go1.drive))go1.tx'
go3.tx = 'getAttr -t (frame-(go1.drive*2))go1.tx'

I'm just trying to get 'go2' to repeat the animation that 'go1' has made with 'drive' frames as a delay number

and multiplying that number for 'go3'

0 Likes