Search code examples
c++pythonmaya

Equivalent of maya.cmds in C++


I was wondering if there was any equivalent to maya.cmds in C++!

I would imagine it as something like:

MPxCommand *objectTypeCmd = MPxCommand::getCommand("objectType");
MArgList args;
args.add("particleShape1");
objectTypeCmd->doIt(args);

if (objectTypeCmd->currentResultType()== MPxCommand::kString)
  MGlobal::displayInfo(objectTypeCmd->currentStringResult());

Any way more direct than calling MEL or Python from C++ code ?

Note that half of the function used here for MPxCommand are improperly used or doesn't exists at all! It's just to explain what I want to do.


Solution

  • No. The scripting interface and the C++ interface have different purposes. These purposes do not overlap. You can not even do half of the things available in the scripting interface with Maya C++ API. When it is possible the c equivalent code is thousands of times longer than the script code. Just keep calling the scripts.

    However python itself does have a c interface, so you can call python commands with this interface (see embedding python). However its really heavy work and you will still be calling the scripting layer (with all speed and other implications).

    for more info read: New To The Api? Then Read This! The article predates the python interface but its still extremely accurate.