/*
Use NestedObjects to do a Brute Force Recursion
through the entire scene to find all custom properties
This will be slow because it goes through entire scene
but this basic approach can be modified to do many
types of searches. (For a fast approach see the CustomProperty
example located at the FindObjects command reference)
*/
SetupDemoScene() ;
// Results are accumulated into these
// global variables
var g_cntTestedElements = 0 ;
var g_oCol = new ActiveXObject( "XSI.Collection" ) ;
// Doing a recursive search may visit
// the same object more than once
g_oCol.Unique = true ;
FindCustomProperties( ActiveSceneRoot ) ;
ShowResults() ;
function ShowResults()
{
Application.LogMessage( "Searched " + g_cntTestedElements + " objects to find Custom Properties" ) ;
for ( var i = 0 ; i < g_oCol.Count ; i++ )
{
// Our search was very general, so we
// found every single Custom Property
// We can do further tests at this stage,
// for example based on the object
if ( g_oCol(i).Type == "CustomColor" )
LogMessage( "Found CustomColor " + g_oCol(i).FullName ) ;
else
LogMessage( "Found CustomProperty " + g_oCol(i).FullName ) ;
}
}
function FindCustomProperties( oParent )
{
var oChildren = oParent.NestedObjects ;
for ( var i = 0 ; i < oChildren.Count ; i++ )
{
var oChild = oChildren.Item( i ) ;
TestObject( oChild ) ;
// Note: If you have some ideas about
// where the object is you can make the
// search faster by skipping this call
// for some types of objects. For example
// you could avoid shader trees by
// stopping at any material objects,
FindCustomProperties( oChild ) ;
}
}
// This function is called for every single
// object in the scene
function TestObject( oObj )
{
g_cntTestedElements++ ;
if ( oObj.IsClassOf( siCustomPropertyID ))
{
g_oCol.Add( oObj ) ;
}
}
// Build an example scene with Custom Properties
// tucked into various locations.
function SetupDemoScene()
{
newscene( null, false ) ;
// CustomColor is a self-installed Custom Property
ActiveSceneRoot.AddProperty( "CustomColor", false, "MyColor" ) ;
ActiveSceneRoot.AddProperty( "CustomColor", false, "MyColor2" ) ;
ActiveSceneRoot.AddProperty( "CustomProperty", false, "MyEmptyCustomProp" ) ;
oSphere = ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" ) ;
oCls = oSphere.ActivePrimitive.Geometry.AddCluster( "edge", "MyCluster" ) ;
oCls.AddProperty( "CustomColor", false, "MyColor" ) ;
oSphere.AddMaterial( "Phong" ) ;
var oPhongShader = oSphere.Material.Shaders(0)
oPhongShader.AddProperty( "CustomProperty", false, "EmptyNestedProp" ) ;
oPhongShader.AddProperty( "CustomProperty", false, "MyColor" ) ;
var oModel = ActiveSceneRoot.AddModel(null, "MyModel" ) ;
oModel.AddProperty( "CustomColor", false, "MyColor3" ) ;
oModel.AddProperty( "CustomProperty", false, "EmptyProperty" ) ;
oModel.AddNull().AddProperty( "CustomColor", false, "MyColor4" ) ;
}
//Expected results (number of objects searched may vary)
//INFO : Searched 2922 objects to find Custom Properties
//INFO : Found CustomColor MyColor
//INFO : Found CustomColor MyColor2
//INFO : Found CustomProperty MyEmptyCustomProp
//INFO : Found CustomColor sphere.polymsh.cls.MyCluster.MyColor
//INFO : Found CustomProperty sphere.Material.Phong.EmptyNestedProp
//INFO : Found CustomProperty sphere.Material.Phong.MyColor
//INFO : Found CustomColor MyModel.MyColor3
//INFO : Found CustomProperty MyModel.EmptyProperty
//INFO : Found CustomColor MyModel.null.MyColor4 |