コマンドから返される値を取得するには、戻り値から変換します 。たとえば、AddImageSource コマンドは、新しいイメージ ソースを表す Source オブジェクトを返します。
Application app; CValue retVal;CValueArray inArgs(2); inArgs[0]= CValue();// default: prompts user for location inArgs[1]= L"MyNewImgSrc"; app.ExecuteCommand( L"AddImageSource", inArgs, retVal ); // The new image source can be extracted from the returned CValue Source sph( retVal ); app.LogMessage( sph.GetFullName() ); /* The following is logged to history: //INFO : Sources.MyNewImgSrc */
コマンドがコレクションを返した場合、CValueArray に変換して該当するクラスに各メンバをキャストすることができます。この例では、2 つの新しいコンストレイントを含むコンストレイント コレクションを返す SIApplyCns コマンドを使用して、2 つのオブジェクトに方向コンストレイントを適用する方法を示しています。
Application app; Model root = app.GetActiveSceneRoot(); // Create a cone and 2 cubes X3DObject cone; root.AddGeometry( L"Cone", L"MeshSurface", L"MyCone", cone ); X3DObject cube1; root.AddGeometry( L"Cube", L"MeshSurface", L"MyCube1", cube1 ); X3DObject cube2; root.AddGeometry( L"Cube", L"MeshSurface", L"MyCube2", cube2 ); CValue retVal; CValueArray inArgs(4); inArgs[0] = L"Orientation"; inArgs[1] = cube1.GetFullName() + L"," + cube2.GetFullName(); inArgs[2] = cone.GetFullName(); inArgs[3] = CValue(); // default: false app.ExecuteCommand( L"SIApplyCns", inArgs, retVal ); // The new constraints can be extracted from the returned CValue CValueArray cnslist( retVal ); for ( LONG i=0; i<cnslist.GetCount(); ++i ) { Constraint cns( cnslist[i] ); app.LogMessage( cns.GetFullName() ); } /* The following is logged to history: //INFO : MyCube1.kine.oricns //INFO : MyCube2.kine.oricns */