Application::ExecuteCommand 関数を使用して、C++ API プロジェクト内から Softimage ネイティブ コマンドとカスタム コマンドを呼び出すことができます。ExecuteCommand 関数には、必須の引数が 3 つあります。
in_name: コマンド名を示す入力 CString 値(L"Translate" など)
in_args: そのコマンドの引数のリストを含む入力 CValueArray(「コマンドおよびスクリプト リファレンス」に表示される順番と同様)
io_val: コマンドからのすべての戻り値を保持する出力 CValue
通常、in_args 配列によるコマンド引数の指定は、比較的簡単なプロシージャです。 次の事項に注意してください。
魅力的または論理的に見えても ArgumentArray は使用しないでください。 ArgumentArrays は、カスタムコマンドを作成または編集するためだけのものです。
配列で null または空の引数を使用して既定値を引数値に強制することができますが、コマンド引数の元の順番は変えないでください。 たとえば、既定値を使用するには次の 3 つの方法があります。
// NewScene command using an empty CValue to force the default CValue outArg; CValueArray inArgs; inArgs.Add( CValue() ); // ProjectPathName inArgs.Add( false );// Confirm app.ExecuteCommand( L"NewScene", inArgs, outArg ); // SaveShapeKey command using undefined values to force the default CValueArray args3(9); CValue out3; args3[0] = target; args3[3] = CValue(1.0); app.ExecuteCommand( L"SaveShapeKey", args3, out3 );
// AddClip command adding only the first three arguments // NOTE: here 'root' is a reference to the Scene_Root and 'src' // is a reference to an ActionSource created previously CValueArray inArgs; CValue outArg; inArgs.Add( root.GetFullName() ); inArgs.Add( src.GetFullName() ); inArgs.Add( root.GetFullName() ); app.ExecuteCommand( L"AddClip", inArgs, outArg );
引数の 1 つとして 列挙値を指定する必要がある場合、LONG として最初にキャストしてから CValue として指定します。これは、enum から CValue に直接キャストすることができないので、最初に LONG に変換する必要があるためです。
// Using the Translate command with the C++ API. This is a good demonstration of both how to // use enums and how to force the default arguments (ie., using undefined argument values) CValue outArg; CValueArray inArgs(19); // initialize with the 19 arguments inArgs[0] = obj.GetFullName(); inArgs[1] = CValue(0.0); inArgs[2] = CValue(-2.0); inArgs[3] = CValue(0.0); inArgs[4] = CValue((LONG)siAbsolute);// double cast for the enums inArgs[5] = CValue((LONG)siPivot); inArgs[6] = CValue((LONG)siObj); inArgs[7] = CValue((LONG)siY); inArgs[17] = CValue((LONG)siConstructionModePrimaryShape); app.ExecuteCommand( L"Translate", inArgs, outArg );// note the 'L' indicating wide character
コマンドで出力引数が使用される場合、io_val 出力引数を使用してアクセスする必要があります。 入力引数配列の一部としてポインタをパスすることはできません。ポインタはコマンドの実行後も初期化されません。 io_val から出力引数を抽出する方法については、「出力引数を操作する」を参照してください。