Integrating 3D models with photography
Interested in integrating your 3D work with the real world? This might help
# 1 14-01-2003 , 10:02 AM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198

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. user added image

I hope you understood...

user added image


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 2 14-01-2003 , 10:41 AM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
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
# 3 14-01-2003 , 10:52 AM
Kevin
Guest
Posts: n/a
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!

# 4 14-01-2003 , 12:48 PM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
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 user added image


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 5 14-01-2003 , 07:27 PM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
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. user added image

-- Mark


Mark R. Wilkins
author of MEL Scripting for Maya Animators
www.melscripting.com
# 6 14-01-2003 , 10:05 PM
kbrown's Avatar
Moderator
Join Date: Sep 2002
Location: London, UK
Posts: 3,198
: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 user added image

Thanks again,


Kari
- My Website
- My IMDB

Do a lot, Fail a lot and Learn a lot!
# 7 14-01-2003 , 10:59 PM
mark_wilkins's Avatar
Registered User
Join Date: Jan 2003
Posts: 161
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
Posting Rules Forum Rules
You may not post new threads | You may not post replies | You may not post attachments | You may not edit your posts | BB code is On | Smilies are On | [IMG] code is On | HTML code is Off

Similar Threads