SubComponent

Object Hierarchy | Related C++ Class: SubComponent

Inheritance

SIObject

SubComponent

Introduced

v2.0

Description

Provides access to sub-elements of an X3DObject's Geometry. The most common uses for the SubComponent object include:

- Accessing the components that are selected (see CollectionItem.SubComponent and Selection.Item)

- Accessing a geometry-specific collection of components on an object (see SubComponent.ComponentCollection)

- Dynamically working with a subset of components (see SubComponent.AddElement and SubComponent.RemoveElement)

Methods

AddElement CreateCluster IsClassOf operator IsEqualTo operator
RemoveElement      
       

Properties

Application Categories ClusterType ComponentCollection operator
ElementArray FullName operator Help Name operator
NestedObjects Origin OriginPath Parent
Parent3DObject Type operator Type  
       

Examples

1. JScript Example

/*
	This example demonstrates how to determine which edges are selected
	in the UI by using the SubComponent object via the Selection
*/ 
NewScene( null, false );
// Setup: create a polygon mesh and select some edges on it
var disc = Application.ActiveSceneRoot.AddGeometry( "Disc", "MeshSurface" );
Selection.Clear();
Selection.SetAsText( disc.Name + ".edge[113,115,117,119,121]" );
// When components are selected, the first member of the Selection
// is returned as a CollectionItem which can then be converted to a
// SubComponent object. From there, the ComponentCollection property
// converts it to the proper collection type (in this case an EdgeCollection)
var selected = Selection(0).SubComponent.ComponentCollection;
for (var i=0; i<selected.Count; i++) {
	var sel = selected(i);
	Application.LogMessage( "edge[" + sel.Index + "] is selected." );
}
// Expected results:
//INFO : edge[113] is selected.
//INFO : edge[115] is selected.
//INFO : edge[117] is selected.
//INFO : edge[119] is selected.
//INFO : edge[121] is selected.

2. Python Example

#
# This example demonstrates how to access a NURBS-specific property
# on a NurbsSurfaceMesh. First it starts out getting the generic
# Points collection. From the PointCollection it creates a SubComponent.
# From the SubComponent, it gets the NURBS-specific ControlPointCollection
# 
app = Application
app.NewScene( "", 0 )
# Setup: create a NURBS mesh and get its point collection
grid = app.ActiveSceneRoot.AddGeometry( "Grid", "NurbsSurface" )
pnts = grid.ActivePrimitive.Geometry.Points
# Convert it to SubComponent and just for fun, consider only ten points 
# chosen at random
subcmp = pnts.SubComponent
subset = [13, 92, 24, 65, 11, 2, 4, 64, 100, 111]
subcmp.ElementArray = subset
# Now convert the SubComponent to a ControlPointCollection using the
# SubComponent.ComponentCollection property and then loop through the 
# array, checking to see if we have any boundaries
for ctrlpnt in subcmp.ComponentCollection :
	msg = "CtrlPnt[" + str(ctrlpnt.Index) + "]"
	if ctrlpnt.IsBoundary :
		msg += " on the NurbsSurface and is a boundary." 
	else :
		msg += " on the NurbsSurface and is NOT a boundary." 
	app.LogMessage( msg )
# Expected results:
#INFO : CtrlPnt[13] on the NurbsSurface and is NOT a boundary.
#INFO : CtrlPnt[92] on the NurbsSurface and is NOT a boundary.
#INFO : CtrlPnt[24] on the NurbsSurface and is NOT a boundary.
#INFO : CtrlPnt[65] on the NurbsSurface and is a boundary.
#INFO : CtrlPnt[11] on the NurbsSurface and is a boundary.
#INFO : CtrlPnt[2] on the NurbsSurface and is a boundary.
#INFO : CtrlPnt[4] on the NurbsSurface and is a boundary.
#INFO : CtrlPnt[64] on the NurbsSurface and is NOT a boundary.
#INFO : CtrlPnt[100] on the NurbsSurface and is NOT a boundary.
#INFO : CtrlPnt[111] on the NurbsSurface and is a boundary.

3. JScript Example

// Create a sample scene and select four points on a grid
var oGrid = ActiveSceneRoot.AddGeometry( "Grid", "NurbsSurface" ) ;
SelectObj( oGrid ) ;
ActivateVertexSelTool();
AddToSelection(oGrid.Name+".pnt[(0,0),(1,0),(2,0),(3,0)]", null, true);
// Print out information that is available from the OM
Application.LogMessage( ClassName( Selection(0) ) ) ;
var oSubComponent = Selection(0).SubComponent ;
Application.LogMessage( oSubComponent.Parent3DObject ) ;
Application.LogMessage( oSubComponent.Type ) ;
Application.LogMessage( ClassName( oSubComponent.ComponentCollection ) ) ;
Application.LogMessage( oSubComponent.ComponentCollection.Count ) ;
// Result of running this script:
//INFO : "CollectionItem"
//INFO : "grid"
//INFO : "pntSubComponent"
//INFO : "PointCollection"
//INFO : "4"

See Also

PointCollection.SubComponent SegmentCollection.SubComponent FacetCollection.SubComponent CollectionItem.SubComponent Geometry.CreateSubComponent Cluster.CreateSubComponent ClusterTypes