コマンド・プラグインによって新しいMELコマンドを作ることができる。
コマンド・プラグインのクラスはMPxCommandクラスを継承して作られる。
class commandName : public MPxCommand ← commandNameというMELコマンドが作られる
{
public:
MStatus doIt( const MArgList& args );
static void* creator();
};
MStatus commandName::doIt( const MArgList& args )
static void* commandName::creator()
MStatus initializePlugin( MObject obj )
MStatus uninitializePlugin( MObject obj )
下のプログラムをコンパイルしMAYAにプラグインとしてロードしてMELコマンド(hello)として実行する。
例えば、hello studentと実行するとHello studentと表示される。
#include <stdio.h>
#include <maya/MString.h>
#include <maya/MArgList.h>
#include <maya/MFnPlugin.h>
#include <maya/MPxCommand.h>
class hello : public MPxCommand ← helloというMELコマンドが作られる
{
public:
MStatus doIt( const MArgList& args );
static void* creator();
};
MStatus hello::doIt( const MArgList& args )
{
↓ コマンドを実行するとHello "引数" と表示する
printf("Hello %s\n", args.asString( 0 ).asChar() );
return MS::kSuccess;
}
void* hello::creator()
{
return new hello;
}
MStatus initializePlugin( MObject obj )
{
MFnPlugin plugin( obj, "Alias|Wavefront", "1.0", "Any"); ← 決まり文句
plugin.registerCommand( "hello", hello::creator ); ← コマンドの名前とcreatorメソッド
return MS::kSuccess;
}
MStatus uninitializePlugin( MObject obj )
{
MFnPlugin plugin( obj );
plugin.deregisterCommand( "hello" ); ← コマンドの名前
return MS::kSuccess;
}