スクリプト コマンドの場合、Execute コールバックでコマンドと同じ引数を取ります。 引数を追加した順番に応じて、Softimage がデータを Execute コールバックに渡す方法が決まります。
// [ JScript ]
function MyCommand_Init( ctxt )
{
// Get the Command object from the callback context
var oCmd;
oCmd = ctxt.Source;
// Get the ArgumentCollection
var oArgs;
oArgs = oCmd.Arguments;
oArgs.AddWithHandler("Arg0","Collection");
oArgs.Add( "Arg1", siArgumentInput, false );
return true;
}
function MyCommand_Execute( Arg0, Arg1 )
{
...
}C++ コマンドでは、コマンド引数を含む Context オブジェクトを Arguments 属性で取得します。
// C++
XSIPLUGINCALLBACK CStatus MyCommand_Execute( CRef& in_ctxt )
{
Context ctxt( in_ctxt );
CValueArray args = ctxt.GetAttribute(L"Arguments");
CValue objects = args[0];
CValue flag = args[1];
#ifdef _DEBUG
Application app;
for (long i=0; i<args.GetCount(); i++)
{
app.LogMessage( L"Arg" + CValue(i).GetAsText() + L" : "
+ L"DataType = " + CValue( (long)args[i].m_t ).GetAsText() );
}
#endif
...
return CStatus::OK;
}Arguments 属性は CValueArray です。この配列の各エレメントは、引数を格納する CValue オブジェクトであり、ブール、数値、文字列値、単一の Softimage オブジェクト、またはオブジェクトのコレクションなどになります。たとえば、Collection 引数ハンドラを使用して引数を追加する場合は、次のようになります。
oArgs.AddWithHandler( L"objects", L"Collection" );
これで、引数の CValueArray に、オブジェクトのコレクションを格納する CValue エレメントが追加されます。
XSIPLUGINCALLBACK CStatus MyCommand_Execute( CRef& in_ctxt )
{
Context ctxt( in_ctxt );
CValueArray args = ctxt.GetAttribute(L"Arguments");
// CValue::operator CValueArray() automatically converts
// args[0], which is a CValue, to a CValueArray
CValueArray objects = args[0];
for (long i=0; i<objects.GetCount(); i++)
{
// objects[i] is a CValue object that holds a CRef to an object
CRef ref = objects[i]; // CValue::operator CRef() does the conversion for us
if ( ref.GetClassID() == siX3DObjectID )
{
// Construct an X3DObject from the CRef
X3DObject obj( ref );
...
}
}
...
}SDK コマンド ウィザードを使用して C++ コマンドを作成する場合、常に、次のように引数が CValue オブジェクトに割り当てられます。
CValue Arg0 = args[0]; CValue Arg1 = args[1];
ただし、args[i]は CValue であり、CValue クラスは代わりに次のことを行う変換オペレータのセットを提供します。
CValueArray objects = args[0]; // arg that uses the Collection arg handler CRef obj_ref = args[1];// arg that uses the SingleObj arg handler bool flag = args[1];// boolean arg CString name = args[2];// string arg