SIObject.NestedObjects

導入

v5.0

詳細

このオブジェクトの下にネストされているオブジェクトの SIObjectCollection を戻します。関数から戻されるネストされているオブジェクトは、PropertyParameterX3DObject などのシーンオブジェクトです。ネストされているオブジェクトがない場合はコレクションは空になります。

C#構文

// get accessor

SIObjectCollection rtn = SIObject.NestedObjects;

1. VBScript の例

'

' This example traverses the hierarchy of a selected object and logs 

' recursively all its nested objects.

'

' Note: Although this example sets up its own selection, you 

' could remove the SETUP section and run this example with

' your own selection instead.

'

' SETUP

NewScene , false

set arc = CreatePrim( "Arc", "NurbsCurve" )

set disc = CreatePrim( "Disc", "MeshSurface" )

CreatePrim "Cylinder", "MeshSurface"

set oSelection = Application.Selection

oSelection.Clear

oSelection.Add arc

oSelection.Add disc

' MAIN

set obj = Application.Selection(0)

VisitNestedObjects obj, 0 

' RESULTS

'INFO : X3DObject:arc

'INFO :  Parameter:Name:arc

'INFO :  Parameter:Primitive:

'INFO :   Primitive:Arc

'INFO :    Parameter:Radius:4

'INFO :    Parameter:Start Angle:0

'INFO :    Parameter:End Angle:90

'INFO :   Primitive:NURBS Curve List

'INFO :    SIObject:Clusters

'INFO :     Parameter:Point

'INFO :      Parameter:Cluster List

'	etc.

' HELPER

sub VisitNestedObjects( obj, indent )

	dim strMsg, nestees, nestedobj

	strMsg = String( indent, " " ) & TypeName(obj) & ":" & obj.Name

	' Turn on error trapping (in some cases parameter values 

	' are not accessible using the Value property)

	on error resume next

	if obj.IsClassOf( siParameterID ) then

		' Log the parameter value if any

		strMsg = strMsg & ":" & obj.Value

	end if

	' Turn off error trapping 

	on error goto 0

	Application.LogMessage strMsg

	' Traverse recursively all nested objects

	set nestees = obj.NestedObjects

	for each nestedobj in nestees

		VisitNestedObjects nestedobj, indent+1

	next

end sub

2. JScript の例

/*

	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

関連項目

EnumElements FindObjects SIObject.Parent SceneItem.Properties ProjectItem.Owners X3DObject.Models X3DObject.Children