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.

proc int doThis(){
    // code to snap something
proc string doThat(){
    // code to unsnap something 
proc callScriptNodes(string $p_name) 
    // In case file is referenced
    string $sNodes[] = `ls  ("*"+$p_name)`;

    for ($i=0; $i < size($sNodes); $i++)
       scriptNode  -eb $sNodes[$i]; 
// Call the main scriptNode(s) to load other nodes
// Load other script nodes
$win = `window ...`;
$sliderL = `attrFieldSliderGrp -min -0 -max 10.0 -at ($leftFeet+".tz") -l "Left Feet"`;
showWindow $win;

MEL: Cleaning Memory

One of the problems with MEL is that we don't have much control over deleting variables from memory. The only command available for this purpose is clear and it only works with array. But, we can use this function to clear up very long string data.

We can store string variables in an array for cases where string holds a large amount of data (string holding a script). In this case we can clear the array and it will also free the memory occupied by the string data. But we should only use this wisely as it can lead to the code that is difficult to read. So here is an example.
string $data[5];
$data[1] = "scriptNodeName";
$data[0] = `scriptNode -q -bs $data[1]`;
// Do processing here
clear $data;

08 March, 2010

Dirty Bit Propagation

I have been looking for more information on how and when Maya marks nodes dirty. First thing I have come to understand is that for an attribute two dirty bits can be set, connection and datablock. See isDirty command for these two options. I am still not clear how using these two flags Maya decides to call compute method. And what has confused me more is that if I don't mark a datablock clean then the compute method does not get called after first compute call.
Here is an interesting discussion about dirty propagation,

07 March, 2010

compute Method and Dirty Bit

Working at the lower level functioning of Maya, is a very different experience as there are lots of obvious elements to consider. Basic rule of Maya is that a node is computed only if there is a need of new output from that node. So if there is no output attribute or if it's not connected  then the node is not computed. There has to be another node dependent on output of our node for Maya to call compute method of our node. And we have to explicitly mark a plug clean to tell maya that the output is latest.

Technically not entirely correct post. I will be posting a new elaborated post explaining this matter.