To get at the value returned from a command, you convert it from the returned . Ror example, the AddImageSource command returns a Source object representing the new image 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 */
If the command returns a collection you can convert it to a CValueArray and then cast each member to its proper class. This example demonstrates how to apply an orientation constraint to two objects using the SIApplyCns command which then returns a constraint collection containing the two new constraints:
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
*/