
hohehohe2's OpenMaya tutorial
kotamuraa@yahoo.co.jp
Executing a MEL command
(All codes in this page are not tested)
When you write a plug-in, you often think if you can use MEL
command.
Because it is easier, also in some cases, API cannot do the same thing
as a MEL command does.
You can execute MEL command from within your plug-in
MGlobal::executeCommand()
MDGModifier::commandToExecute()
Both of them takes a MEL command as a string (MString) parameter
and
execute it immediately (?).
Example1:
double txValue;
MGlobal::executeCommand("getAttr nurbsSphere1.tx",
txValue);
Example2:
MDGModifier dmod;
dmod.commandToExecute("sphere -p 0 0 1");
Each of them has its own characteristics.
MGlobal::executeCommand()
- Cannot undo from within your plug-in.
- Can get the result of the command.
MDGModifier::commandToExecute()
- Can undo from within your plug-in.
- Cannot get the result of the command.
When the MEL command changes the scene (so the plug-in changes the
scene),
you must make the plug-in undoable, you need to undo the MEL
command in undoIt(). So you cannot use MGlobal::executeCommand().
(In some cases setting the undoEnabled parameter of MGlobal::executeCommand()
to true may be OK, but I don't think it's a good idea. (?))
On the contrary, you cannot use MDGModifier::commandToExecute() to execute
non undoable
MEL commands.
To get the result of the MEL command using MGlobal::executeCommand(),
if the result is one of these, int, int array, double, double array,
string, string array,
the code will be like this,
int result;
MGlobal::executeCommand("MEL command", result);
MintArray result;
MGlobal::executeCommand("MEL command", result);
and so on.
If the result is vector or vector array or matrix or matrix array,
no MGlobal::executeCommand()
is prepared for that, so the code will be like this,
MCommandResult result;
MGlobal::executeCommand("MEL command", result);
MVector vector;
result.getResult(vector);
and so on
I didn't check MStatus here for simplicity.
Contents
Maya is a registered
trademark of Autodesk
Copyright ©
2003, Koichi Tamura. All Rights Reserved.