Interacting with Softimage
 
 
 

This section provides a number of examples of how to use C# to interact with Softimage. For more information on each individual class, see the Object Model documentation in the Commands and Scripting Reference.

Note

The following code fragments comprise a sampling of how to use Softimage Object Model with C#. For more extensive examples, see the following examples installed with Softimage:

C# Example: connecting to Softimage

You can access Softimage by creating an instance of the XSIApplication object with the new keyword:

using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Tip

Besides the XSIApplication class, you must use this syntax to create instances of the following objects:

C# Example: creating an X3DObject

The X3DObject.AddGeometry method creates a new X3DObject:

// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;

// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");

C# Example: iterating a list of children

When you don't know the exact interface of the object in a collection of children, you can use the base X3DObject class or test it using the SIObject.IsClassOf method and coerce it to a more specific class:

// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;

// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");

// browse the 3d objects under the scene root
X3DObjectCollection kids = root.FindChildren("", "", "", true);
Log("Total # of kids: " + kids.Count);
foreach (X3DObject thing in kids)
{
	if (thing.IsClassOf(siClassID.siCameraID))
	{
		Camera cam = (Camera)thing;
		Log(cam.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siCameraRigID))
	{
		CameraRig camRig = (CameraRig)thing;
		Log(camRig.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siLightID))
	{
		Light lite = (Light)thing;
		Log(lite.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siLightRigID))
	{
		LightRig liteRig = (LightRig)thing;
		Log(liteRig.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siModelID))
	{
		Model mdl = (Model)thing;
		Log(mdl.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siNullID)) 
	{
		Null n = (Null)thing;
		Log(n.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siX3DObjectID))
	{
		X3DObject obj3d = (X3DObject)thing;
		Log(obj3d.Name);
		continue;
	}
	if (thing.IsClassOf(siClassID.siParameterID))
	{
		Parameter param = (Parameter)thing;
		Log(param.Name);
		continue;
	}
	// etc.
}

C# Example: accessing parameters

Parameter lists are returned in a ParameterCollection with which you can use the handy and reliable foreach loop:

// returns the root object
using XSIOM;
CXSIApplicationClass app = new CXSIApplicationClass();
Model root = app.ActiveSceneRoot;

// create object as a child of the root
X3DObject obj = root.AddGeometry("Torus", "MeshSurface", "Torific");

// find the parameters under the torus
ParameterCollection paramlist = obj.Parameters;
Log("Total # of parameters found: " + paramlist.Count);
foreach (Parameter param in paramlist)
{
	Log(param.Name + " is a " + param.ValueType);
}