Object Model Parsing

In Jscript (or VBscript if need be) how do I parse the Object Model in XSI?

My purpose basically is to access all the objects in a scene and go through each of them one by one.

Thanks,

Vijay @ Dream Interactive....

There's a number of ways to do it. In the example below, the Traverse() function starts with the scene_root and gets a reference to the object's children collection, then iterates thru printing information about each child one-by-one. For sake of example, If the child is a polygon mesh, it's children are traversed until no more polygon mesh children are found.

To do the reverse and traverse up a hierarchy, simply assign the ".parent" reference to the object. When the object's name is identical to the parent's, you've reached the top (eg object.Name == object.Parent.Name)

------------start of script (Jscript)--------------------

// store location of the scene root
var startpoint = Application.ActiveProject.ActiveScene.Root;

// Start the process
traverse( startpoint );

/***********************************************************************
* Traverse() - gets a reference to the input object's children
* and prints general information about them. If a
* child is a mesh, it's children are traversed.
*************************************************************************/
function traverse( startnode )
{
var i, oRoot, oChildren, child;

// verify we're traversing a valid entry point
if ( startnode == null ) {
return( null );
}

oRoot = startnode;

// Get a reference to the children collection
oChildren = oRoot.children;

if ( oChildren.count == 0 ) {
// Object has no children
return( null );
}

// list the children and some background info about them
for ( i = 0; i < oChildren.count; i++ ) {

  // For convenience, get current child from the collection
  child = oChildren(i);

  // List the child's name, type, parent, etc...
  LogMessage( "  Name: " + child.Name,   siInfo );
  LogMessage( "  Type: " + child.Type,   siInfo );
  LogMessage( "Parent: " + child.Parent, siInfo );
  LogMessage( " Model: " + child.Model,  siInfo );
  LogMessage( "Selection status: " + child.Selected, siInfo );
  // Add your own queries here

  // For sake of example, only traverse child's children 
  // if it is a polygon mesh.
  if ( child.type == "polymsh" ) {
     LogMessage( "--- It's a Polygon mesh ---", siInfo );
     traverse( child );
  }

}

return( 0 );
}

------------end of script (Jscript)--------------------

Hope this helps,

Matt


Matt Lind
Animator / Technical Director
Softimage certified instructor:
Softimage|3D
Softimage|XSI
speye_21@hotmail.com