17 March, 2010

ScriptNode and Sequence of Loading

This is from Maya docs,
"If a scene contains several script nodes, there is no guaranteed order of execution and the scripts should not depend on a specific execution sequence."

So this means that there is no way to make sure that a particular script node gets executed first. This creates a problem because If I want to modularize my script nodes and have all the procedures in one scriptNode (so that I can call it from multiple other scriptNodes and I can easily update them) I cannot make sure those procedures will be available before I use them.

One of the workarounds is not to run all the scriptNodes on open/close event. Instead you can only have one scriptNode that is loaded on file open. This scriptNode has all the needed procedures defined at the beginning. At the end we execute another scriptNode that in turn calls all other user defined scriptNodes. Here is a pseudo MEL code explaining the concept. This can be handled with referencing (more coming on that later). However, some care should be taken because a node can be executed more than once in reference mode, but I think that problem is easily solvable.