コマンド・プラグイン

コマンド・プラグインとは

コマンド・プラグインによって新しい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 )
プラグインがアンロードされるときに実行される。
コマンドの登録取消などを行う。

コマンド・プラグインの例1

下のプログラムをコンパイルし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;
}

参考


Prev | Next
Home | Contents
abe@injapan.net