Interacting with XSI

This section provides a number of examples of how to use the C++ API class library to interact with XSI. For more examples of code and information on each individual class, see the C++ API Reference .

 

The following code fragments comprise a sampling of how to use the C++ API. For more extensive examples, see the C++ API Reference .

 

C++ Example: connecting to XSI

// gets the application object, which you can use to communicate with XSI
// eg., 
Application app;
app.LogMessage( "Welcome to XSI!" );

C++ Example: creating an X3DObject

// returns the reference root object
namespace XSI;
Application app;
CRef rootRef = app.GetActiveSceneRoot();

// create object with a reference object
X3DObject rootObj(rootRef);

C++ Example: iterating a list of children

// returns the reference root object
namespace XSI;
CRef rootRef = app.GetActiveSceneRoot();

// create object with a reference object
X3DObject rootObj(rootRef);

// get children recursively
CRefArray childArray = rootObj.FindChildren(L"",L"",L"");
// count number of children
for ( long i=0; i<childArray.GetCount();i++ )
{
   CRef ref = childArray[i];
   if ( ref.IsA( xsi3DObjectType ) )
   {
       dw3DObjectCount++;
   }
   else if ( ref.IsA( xsiModelType ) )
   {
       dwModelCount++;
   }
   else if ( ref.IsA( xsiChainElementType ) )
   {
       dwChainElementCount++;
   }
   else if (ref.IsA( xsiDirectedObjectType ) )
   {
       dwDirectedObjectCount++;
   }
   else if (ref.IsA( xsiNullType ) )
   {
       dwNullCount++;
   }
   else if (ref.IsA( xsiParticleCloudType ) )
   {
       dwParticleCloudCount++;
   }
   else
   {
       dwUnknownCount++;
   }
}

C++ Example: accessing parameters

using namespace XSI;
Application app;

CRefArray array;
GetSomeObjects(array,app);

// Find all X3DObjects in the scene and add them to the ref array
CStringArray emptyArray;
Model root( app.GetActiveSceneRoot() );

array += root.FindChildren( L"", L"", emptyArray, true );

// add grid's parameters to ref array
X3DObject grid;
root.AddGeometry( L"Grid", L"MeshSurface", L"", grid );

array += grid.GetParameters();

for (long i = 0; i < array.GetCount(); ++i )
{
   app.LogMessage(L"");

   CRef ref(array[i]);
   app.LogMessage( L">>Reference object class type: " + ref.GetClassName() );

   if ( ref.IsA( siSIObjectID ) )
   {
       SIObject siobj(ref);
       app.LogMessage( L"\tObject name: " + siobj.GetName() );
   }

   if ( ref.IsA( siX3DObjectID ) )
   {
       X3DObject xobj(ref);
       app.LogMessage( L"\tNumber of children : " 
              + CValue(xobj.GetChildren().GetCount()).GetAsText() );
   }

   if ( ref.IsA( siParameterID ) )
   {
       Parameter param(ref);
       app.LogMessage( L"\tParameter's value: " + param.GetValue().GetAsText() );
   }
}

 



SOFTIMAGE|XSI v6.01     

Return to Softimage XSI Index