Dealing with Output Arguments

XSI uses output arguments in some of its scripting commands (see Working with Output Arguments for an overview of using output arguments with scripting languages in XSI), such as AddProp, GetFCurveInfo, and SICreateImageClip. Although C++ supports output arguments, the updated value is contained inside the CValueArray that got passed in, not inside any variable that might have been used to initialize the value:

   Application app;

   // Trying to get output arguments via the variable
   Camera cam;
   Null camInt;

   CValue retVal;
   CValueArray inArgs(8);
   inArgs[0] = L"Telephoto";
   inArgs[1] = L"MyCamera";
   inArgs[4] = cam;
   inArgs[5] = camInt;
   app.ExecuteCommand( L"SIGetPrimCamera", inArgs, retVal );

   // Testing the 'output' arguments to see if they're valid
   if ( cam.GetRef().IsValid() ) {
       app.LogMessage( cam.GetName() + L" is valid" );
   } else {
       app.LogMessage( L"'cam' is not valid" );
   }

   if ( camInt.GetRef().IsValid() ) {
       app.LogMessage( camInt.GetName() + L" is valid" );
   } else {
       app.LogMessage( L"'camInt' is not valid" );
   }

   /* The following is logged to history:
   'INFO : 'cam' is not valid
   'INFO : 'camInt' is not valid
   */

To extract an output argument, you get it from the input argument array (CValueArray ) and from there you can convert each member of the array from the CValue to its proper data type or class:

   Application app;

   CValue retVal;
   CValueArray inArgs(8);
   inArgs[0] = L"Telephoto";
   inArgs[1] = L"MyCamera";
   inArgs[4] = CValue(); // newly created Camera and Interest are returned as output arguments
   inArgs[5] = CValue();
   app.ExecuteCommand( L"SIGetPrimCamera", inArgs, retVal );

   // The camera is in inArgs[4] and its interest in inArgs[5]
   Camera cam( inArgs[4] );
   Null camInt( inArgs[5] );

   app.LogMessage( cam.GetName() + L" is at position " 
       + CString(cam.GetParameterValue(L"posx")) + L"," 
       + CString(cam.GetParameterValue(L"posy")) + L"," 
       + CString(cam.GetParameterValue(L"posz")) 
   );

   app.LogMessage( camInt.GetName() + L" is at position " 
       + CString(camInt.GetParameterValue(L"posx")) + L"," 
       + CString(camInt.GetParameterValue(L"posy")) + L"," 
       + CString(camInt.GetParameterValue(L"posz")) 
   );

   /* The following is logged to history:
   'INFO : Number of output arguments in the returned array: 4
   'INFO : MyCamera is at position 0,2,20
   'INFO : CameraInterest is at position 0,0,0
   */

 

An easy alternative to using the Application::ExecuteCommand function is to generate command stubs using the cmdstubs_generator.js utility under the <factory location>\XSISDK\utils\cmdstubs directory. See the help page in that same folder for more information.



SOFTIMAGE|XSI v6.01     

Return to Softimage XSI Index