Segment.SubComponent operator

Introduced

v3.0

Description

Creates a SubComponent from this segment. The new SubComponent allows you to access the specific type of Geometry (the Edge for a PolygonMesh object).

C# Syntax

// get accessor
SubComponent rtn = Segment.SubComponent;

Examples

1. VBScript Example

'
' This example demonstrates how to work with a subset of segments on a polygon mesh
'
NewScene , false
dim oObj, oSubComponent 
set oObj = Application.ActiveSceneRoot.AddGeometry("Cube","MeshSurface")
set oSegColl = oObj.ActivePrimitive.Geometry.Edges
set oSubComponent = oSegColl(4).SubComponent
Application.LogMessage oSubComponent & " has " & UBound(oSubComponent.ElementArray)+1 & _
	" components of type " & TypeName(oSubComponent.ComponentCollection(0))
set oObj = Application.ActiveSceneRoot.AddGeometry("Cube","MeshSurface")
set oSubComponent = oObj.ActivePrimitive.Geometry.Edges(7).SubComponent
oSubComponent.AddElement 4
Application.LogMessage oSubComponent & " has " & UBound(oSubComponent.ElementArray)+1 & _
	" components of type " & TypeName(oSubComponent.ComponentCollection(0))
' Expected results:
'INFO : cube.edge[4] has 1 components of type Edge
'INFO : cube1.edge[4,7] has 2 components of type Edge

2. JScript Example

/*
	This example demonstrates how to access a PolygonMesh-specific property.
	First it starts out getting the generic Segments collection. From the 
	SegmentCollection it creates a SubComponent. From the SubComponent, it 
	gets the PolygonMesh-specific EdgeCollection
*/
NewScene( null, false );
// Setup: create a PolygonMesh and get its segment collection
var cyl = Application.ActiveSceneRoot.AddGeometry( "Disc", "MeshSurface" );
var fcs = cyl.ActivePrimitive.Geometry.Segments;
// Convert it to SubComponent and just for fun, select edges in the middle
var subcmp = fcs.SubComponent;
var subset = new Array(23,40,31,12,6,15,22,39);
subcmp.ElementArray = subset;
// Now convert the SubComponent to a EdgeCollection using the
// SubComponent.ComponentCollection property and then loop 
// through the list of Edges, finding whether it is a boundary
var edgs = subcmp.ComponentCollection;
for (var i=0; i<edgs.Count; i++) {
	var results = ( edgs(i).IsBoundary ) ? "" : "NOT ";
	Application.LogMessage( "Edge[" + i + "] at index " + edgs(i).Index 
		+ " is " + results + "a boundary." );
}
// Expected results:
//INFO : Edge[0] at index 23 is a boundary.
//INFO : Edge[1] at index 40 is a boundary.
//INFO : Edge[2] at index 31 is NOT a boundary.
//INFO : Edge[3] at index 12 is NOT a boundary.
//INFO : Edge[4] at index 6 is NOT a boundary.
//INFO : Edge[5] at index 15 is NOT a boundary.
//INFO : Edge[6] at index 22 is NOT a boundary.
//INFO : Edge[7] at index 39 is NOT a boundary.

3. Python Example

#
# This example demonstrates how to determine which edges are selected
# in the UI by using the SubComponent object via the Selection
# 
app = Application
app.NewScene( "", 0 )
# Setup: create a polygon mesh and select some edges on it
disc = app.ActiveSceneRoot.AddGeometry( "Disc", "MeshSurface" )
app.Selection.Clear()
app.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)
selected = app.Selection(0).SubComponent.ComponentCollection
for sel in selected :
	app.LogMessage( "edge[%s] is selected." % (sel.Index) )
# 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.