Mixing the C++ API with the Softimage Object Model

 
 
 

The C++ API provides the CComAPIHandler class and the ConvertObject function to help manage conversions between the C++ API and the Softimage Object Model. The difference between the two is that ConvertObject() gives you a real Automation (ActiveX) object, whereas the CComAPIHandler is a C++ API wrapper for the object model.

CComAPIHandler

The CComAPIHandler class gives you access to members of the Automation object using CComAPIHandler::Call (for methods) and CComAPIHandler::GetProperty and CComAPIHandler::PutProperty (for properties). For example:

// Use the object model version of the Model::AddActionSource() function
ActionSource oSource( in_oSelItem );
CRef oModel = oSource.GetModel().GetRef();

// To define an Automation object in C++ code, use the CComAPIHandler class
CValue retVal;
CComAPIHandler comHandler( oModel.GetRef() );

// Now that you have an instance of the Model interface, you can use the
// CComAPIHandler::Call member to execute the AddActionSource method
comHandler.Call(  L"AddActionSource", retVal, L"OO_" + oSource.GetName() );

This example demonstrates how to use the CComAPIHandler to access the DataRepository object:

CRef oObj = Application().GetSelection().GetItem(0);

CComAPIHandler ccomXSIUtils;

ccomXSIUtils.CreateInstance( L"XSI.Utils");

CComAPIHandler dataRep(ccomXSIUtils.GetProperty( L"DataRepository" )) ; 

XSI::CStatus ret;
CValue ioID;
CValueArray inArgs;
inArgs.Add(CValue(oObj));
inArgs.Add(2L);
ret = dataRep.Call( L"GetIdentifier", ioID, inArgs);

Application().LogMessage(L"Selected Object GUID is " + ioID.GetAsText(),siInfoMsg);

ConvertObject

The global function ConvertObject() converts a CRef object to a Softimage Automation object and vice-versa. This allows you to actually mix the object model and pure C++ inside your code.

// Use the object model version of the Model::AddActionSource() function
ActionSource oSource( in_oSelItem );
CRef oModel = oSource.GetModel().GetRef();

// Pass a CRef to ConvertObject and get an IDispatch* through a void* ptr
ModelPtr oModelCOM = ( IDispatch* )ConvertObject( oModel );

// Now you can use the new pointer to get at the object model methods
ActionSourcePtr oNewSourceCOM = oModelCOM->AddActionSource( "OO_" & oSource.GetName() );

// Convert the new ActiveX Source object back to C++
ActionSource oNewSource = ConvertObject( oNewSourceCOM );