SimplyMaya Forums

Welcome to the forum, feel free to ask questions here.

Register FAQ Members List Calendar Mark Forums Read

New Thread
 
Thread Tools
Old 14-01-2003, 09: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, 09: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, 09: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, 11:48 AM   #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, 06: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, 09: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, 09: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
New Thread

« Previous Thread | Next Thread »

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off

1 Month

$34

Month-to-month billing
$34/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
 
 

3 months

$87

Billing every 3 months
$29/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $5 per month or $15 in total compared to monthly billing with this package.

12 months

$288

Billing every 12 months
$24/month
Unlimited access to all videos
Project files to download
Easy to cancel at anytime
Save $10 per month or $120 in total compared to monthly billing with this package.

Your plan will automatically renew. You can cancel at any time via your PayPal account to avoid being charged again.

You can view the FAQ on our video plans here. You can contact us directly here. By clicking one of the buttons above, you agree to our Terms and Privacy Policy.