AddProp.2.js Example

Applies To

AddProp command

Description

This example demonstrates how to use the AddProp command.

Code

/*
	This JScript example illustrates how to use the AddProp command to add an 
	annotation property to a null object. Of special interest in this example
	is how we use the returned object to extract an array of output arguments
	(since JScript does not support output arguments).

	Note: In this example we are using the XSIApplication.ClassName method 
	which is the equivalent of the VBScript TypeName function (for which
	there is no native JScript equivalent).
*/
NewScene( null , false );
// Add a null to the scene
var oSphere = GetPrim( "Null" );
// Add an annotation to the null; the AddProp command returns the output 
// object as an XSICollection of 1, so you can get the actual annotation 
// as a Property object by resetting the object pointer to the first 
// member of the returned collection
var oRtnColl = AddProp( "Annotation", oSphere, siDefaultPropagation, "Jenny" );
// Test the type of the return value 
PrintInfo( oRtnColl );
// To get the Property object, set the reference to the first member of
// the collection
//var oRMap = oRtnColl(0);

// This is just a utility function to separate the printing procedure
// from the rest of the example
function PrintInfo( in_coll )
{
	// Print the class type (ie., Object, X3DObject, Property, etc.)
	LogMessage( "=========" );
	LogMessage( "ClassName: " + ClassName( in_coll ) );
	// This prevents an error if the specified object is invalid
	if ( ClassName( in_coll ) != "Nothing" ) 
	{
		// This prevents us from trying to use collection functions
		// on a non-collection object (XSICollections returned from
		// commands report that they have the "Object" class type:
		// this is for backwards compatibility)
		if ( ( ClassName( in_coll ) == "Object" && in_coll.Type() == "XSICollection" ) || 
			ClassName( in_coll ) == "ISIVTCollection" )
		{ 
			// ISIVTCollections can be enumerated but they don't 
			// support the Type property, so we'll skip that for
			// ISIVTCollections
			if ( ClassName( in_coll ) == "ISIVTCollection" )
			{
				// Convert the ISIVTCollection to an XSICollection (now 
				// we can continue with the XSICollection-specific tests)
				in_coll = in_coll.item(1);
				// Test it again to make sure it's really an XSICollection
				LogMessage( "Type after conversion: " + in_coll.Type );
			}
			// Loop through the collection and print the name, type and 
			// class type of each item
			LogMessage( "" );
			LogMessage( "This collection contains the following ( " 
				+ in_coll.Count + " ) members ........" );
			for ( i=0; i<in_coll.count; i++ )
			{
				LogMessage( "\tName: " + in_coll.item(i).Name );
				LogMessage( "\tType: " + in_coll.item(i).Type);
				LogMessage( "\tClassName: " + ClassName( in_coll.item(i) ) );
			} 
		}
		else 
		{
			// Print error message 
			LogMessage( "Object is not a collection at all." );
		}
	}
	LogMessage( "End of collection information.................................." );
}

// Output of above script:
//INFO : "========="
//INFO : "ClassName: ISIVTCollection"
//INFO : "Type after conversion: XSICollection"
//INFO : ""
//INFO : "This collection contains the following ( 1 ) members ........"
//INFO : "	Name: Jenny"
//INFO : "	Type: customparamset"
//INFO : "	ClassName: CustomProperty"
//INFO : "End of collection information.................................."

Related Examples

AddProp.1.vbs

Keywords

AddProp


Autodesk Softimage 2011