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.
You can access Softimage by creating an instance of the XSIApplication object with the new keyword:
using XSIOM; CXSIApplicationClass app = new CXSIApplicationClass();
Besides the XSIApplication class, you must use this syntax to create instances of the following objects:
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");
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. }
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); }
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License