Maya Training

Introduction to Hard Surface Modeling

Maya Training

Interiors and Furniture Vol 1 & 2 - Modeling & Cloth

Maya Training

Shading, Lighting and Rendering the Bedroom in MR

Maya Training

Robot volume one - Modeling with animation in mind

Maya Training

Spach-Alspaugh House the complete courseware

Maya Training

Burt The Cartoon Dinosaur Vol 01 - Modeling

New Maya Training

Robot Volume 02 - Hybrid Rigging
You are here > Home > SimplyMaya Community Forums
Loading

Welcome to Simply Maya

Please Sign in or Sign up for an account

Member Login

Lost your password?

Not a member yet? Sign Up!

Old 14-01-2003, 10:02 AM   #1
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default Execution order?

Is there a way to tell maya which expression gets executed first?

My Stormy Ocean project is full of expressions and one of them contains some global variable initializations. Now every time I load the scene I get a bunch of errors because some of the expressions, which uses those global variables, gets executed before the variables are defined.

I've worked my way out of this by going through the expressions and hitting the edit button in the expression editor (the global thingie first). It's not a biggie but kind of annoying.

I hope you understood...

__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 14-01-2003, 10:41 AM   #2
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

Nooooooo

you can't rely on expressions being executed in any particular order.

The way to do this is to make a script node with your initializations and set its execution attribute to run the script on scene open. Then, you're guaranteed that everything will end up initialized.

However, I'm curious -- why not use custom attributes instead of global variables? This would allow Maya to be more intelligent about recalculating your expressions -- in fact, I'm surprised you can get away with using global variables that way at all, because if the global variable changes value there's nothing (meaning no connection in the DG) to let Maya know that all the dependent expressions need to be recalculated, so it must just recalculate all of them every time...

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 14-01-2003, 10:52 AM   #3
Kevin
 
Posts: n/a
Default

nice answer mark!

say mate just noticed you book is only 34.97 at amazon!!

I will be purchasing next week - say the only trouble is ..if i ever bring out a tutorial that goes over mels ...you will be thinking I ripped you off!

lol

Still not to worry mate if it ever comes to that I can always give you a good plug for your book!
  Reply With Quote
Old 14-01-2003, 12:48 PM   #4
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default

Thanks for the prompt answer Mark. I knew I was missing something. I think I now know how to do it properly.

Why do I use global variables? I use them to store some global information like wind direction which is calculated in an expression based on a helper object's (an arrow) rotation. My particle system and fields uses then this information extensively. I got this idea from the Secrets Of The Pros book. It's true I could use custom attributes directly but I prefer it this way (at least for this kind of implementation). I don't know if it's any faster but at least it keeps the channel boxes clean
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 14-01-2003, 07:27 PM   #5
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

Remember, custom attributes do not have to appear in the channel box, nor do they have to be keyable. If you make them non-keyable, they won't appear in the channel box in any case. Also, if you use the addAttr command to make them, you can use the -hidden option which will leave the attribute keyable but will keep it from appearing in either the attribute editor or the channel box.

Let me be more clear about why using global variables in this way concerns me: Maya does a fairly complex analysis of the connections between nodes in your scene to make sure that it's recalculating what needs to be recalculated for each frame. If the *attributes* connected to an object expression node (which is not strictly applicable to your case because you're using particle expressions, which are different) do not change, that expression will never be recalculated, even if the expression itself depends on data you've gotten from other kinds of sources, like from a call to a MEL command like getAttr (which does not form a connection in the DG to your expression node) or from a global variable.

Also, Maya uses these connections to figure out in what order to execute expressions. When you use global variables or getAttr to grab data from elsewhere in the scene, Maya can't always figure out how to correctly evaluate the scene, which is what you've experienced. This means that when your scene does update it may update incorrectly.

The reason you've not had the first kind of problem (where things don't update at all, instead of updating incorrectly) is that you're using this approach with particle expressions, which are guaranteed to run every frame for every particle, instead of with object expressions, which are not so guaranteed. Even so, you still can't count on your scene being evaluated in any particular order unless you have the DG connections in place to let Maya know that it needs to evaluate things a certain way -- and that might mean making custom attributes.

There may be a safe way to use global variables in this way, and I have no doubt that it works some of the time, but I'm not sure that I know what the preconditions are for such an approach working and I VERY much doubt that Secrets of the Pros discusses that aspect of the problem.

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote
Old 14-01-2003, 10:05 PM   #6
kbrown
Moderator
 
kbrown's Avatar
 
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
Thanks: 0
Thanked 8 Times in 8 Posts
Default

:wow: I stand corrected.

I tried the script node approach you mentioned earlier and ran in to other trouble. I now believe you're totally right. Many thanks for the time you spent answering.

Trial and Error is my second and third name. You just got to push every button and see what happens

Thanks again,
__________________
Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
kbrown is offline   Reply With Quote
Old 14-01-2003, 10:59 PM   #7
mark_wilkins
Registered User
 
mark_wilkins's Avatar
 
Join Date: Jan 2003
Posts: 161
Thanks: 0
Thanked 1 Time in 1 Post
Default

well, let us know what you figure out!! :-)

I should experiment a bit with the global-variables-and-expressions thing just to see what I can find out about using them...

-- Mark
__________________
Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
mark_wilkins is offline   Reply With Quote

A little bit about who we are
Links you might find useful
Catch up with SimplyMaya
SimplyMaya specialises in Maya tutorials. We offer over 1,000 individual Maya training videos, ranging from basic Maya tutorials through to intermediate Maya tutorials. Our tutorials are created by instructors with industry experience and are designed to get you up and running in Maya quickly without making it seem like hard work.

Copyright © 1999-2015 SimplyMaya - vBulletin® Copyright © 2000-2015, Jelsoft Enterprises Ltd.