Managing numerous and complex MEL scripts and plug-ins can become difficult and inconsistent in production environments. The following steps will ensure that your MEL scripts get sourced and your plug-ins will get loaded without error and with consistency throughout your production environment.
3) Dealing with loadPlugin and the commands from the plug-in:
In this situation the userSetup.mel has MEL code like the following and gives you errors.
loadPlugin A;
source "B.mel";
someCommandFromThePluginA();
(someCommandFromThePluginA which is sitting inside B.mel that is recognized only when the plugin A is loaded.) ...and you later run the command which comes from the B.mel file. It fails if it references anything from the plugin 'A'.
The solution is:
loadPlugin A;
evalDeferred("source \"B.mel\"");
someCommandFromThePluginA();
The eval causes the eval'ed string to be compiled at runtime. By that point the plug-in is loaded and available. MEL considers source statements as compiler directives, so they are handled before the script is even run. The only way to get around that is to wrap the source statement in an eval.
Another working example of this would be:
string $plugin = "/usr/aw/maya5.0/bin/plug-ins/Mayatomr.so";
loadplugin($plugin);
int $ret=0;
while ($ret == 0)
{
$ret = `pluginInfo -q -loaded $plugin;`
}
eval ("Mayatomr -mi -file " + $inFile + " -perframe 2 -padframe 0
-tabstop 8");
The loadPlugin and evalDeferred execute right away in batch mode since there is no such thing as "idle" in batch mode.
You can NEVER load a plug-in and expect to be able to use a command from that plug-in directly in the same .mel file.
So does it mean that for the most part, loadPlugin is a trivial to the point of being a "useless" MEL command? Well...not quite. Most people write wrapper scripts to load the plug-in and then call something else.
In apiAnimCurveTest.mel try something like:
global proc int
apiAnimCurveTest ()
{
string $soName = "apiAnimCurveTest";
if (`exists Win32Init`)
{
$soName = $soName + ".mll";
}
else
{
$soName = $soName + ".so";
}
// Make sure we can load our plugin
//
if (!`pluginInfo -query -loaded $soName`)
{
if (catch (`loadPlugin $soName`))
{
print ("### apiAnimCurveTest: Fatal error (startup): unable to load
" + $soName + "\n");
return (1);
}
}
// Force apiAnimCurveTestReal.mel to be reparsed by mel
//
eval ("source apiAnimCurveTestReal.mel");
int $errors = eval ("apiAnimCurveTestReal");
return ($errors);
}
And then apiAnimCurveTestReal.mel can use the plug-in commands:
global proc int
apiAnimCurveTestReal ()
{
string $soName = "apiAnimCurveTest";
if (`exists Win32Init`)
{
$soName = $soName + ".mll";
}
else
{
$soName = $soName + ".so";
}
// Make sure our plugin has been loaded
//
if (!`pluginInfo -query -loaded $soName`)
{
print ("### apiAnimCurveTest: Fatal error (startup): unable to load "
+ $soName + "\n");
return (1);
}
// Create some animation
//
apiAnimateAnObject;
return (0);
}
Comments