Facet.SubComponent operator

Introduced

v2.0

Description

Creates a SubComponent from this facet. The new SubComponent allows you to access the specific type of Geometry, such as a PolygonFace for a PolygonMesh object vs. a NurbsSurface for a NurbsSurfaceMesh.

C# Syntax

// get accessor
SubComponent rtn = Facet.SubComponent;

Examples

1. VBScript Example

'
' This example demonstrates how to work with a subset of facets on a polygon mesh
'
NewScene , false
dim oObj, oSubComponent 
set oObj = Application.ActiveSceneRoot.AddGeometry("Cube","MeshSurface")
set oFacetColl = oObj.ActivePrimitive.Geometry.Facets
set oSubComponent = oFacetColl(2).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.Facets(2).SubComponent
oSubComponent.AddElement 3
Application.LogMessage oSubComponent & " has " & UBound(oSubComponent.ElementArray)+1 & _
	" components of type " & TypeName(oSubComponent.ComponentCollection(0))
' Expected results:
'INFO : cube.poly[2] has 1 components of type PolygonFace
'INFO : cube1.poly[2,3] has 2 components of type PolygonFace

2. JScript Example

/*
	This example demonstrates how to access a PolygonMesh-specific property.
	First it starts out getting the generic Facets collection. From the 
	FacetCollection it creates a SubComponent. From the SubComponent, it gets 
	the PolygonMesh-specific PolygonFaceCollection
*/
NewScene( null, false );
// Setup: create a PolygonMesh and get its facet collection
var grid = Application.ActiveSceneRoot.AddGeometry( "Grid", "MeshSurface" );
var fcs = grid.ActivePrimitive.Geometry.Facets;
// Convert it to SubComponent and just for fun, consider only four facets 
var subcmp = fcs.SubComponent;
var subset = new Array(27,28,35,36);
subcmp.ElementArray = subset;
// Now convert the SubComponent to a PolygonFaceCollection using the
// SubComponent.ComponentCollection property and then loop through the 
// list of PolygonFaces, getting its adjacent neighbors
var polyfaces = subcmp.ComponentCollection;
for (var i=0; i<polyfaces.Count; i++) {
	Application.LogMessage( "PolygonFace[" + i + "] at index " + polyfaces(i) + " is next to..." );
	var adjacent = polyfaces(i).NeighborPolygons();
	for (var j=0; j<adjacent.Count; j++) {
		Application.LogMessage( "\t...the PolygonFace at index " + adjacent(j).Index );
	}
}
// Expected results:
//INFO : PolygonFace[0] at index PolygonFace is next to...
//INFO : 	...the PolygonFace at index 19
//INFO : 	...the PolygonFace at index 28
//INFO : 	...the PolygonFace at index 35
//INFO : 	...the PolygonFace at index 26
//INFO : PolygonFace[1] at index PolygonFace is next to...
//INFO : 	...the PolygonFace at index 20
//INFO : 	...the PolygonFace at index 29
//INFO : 	...the PolygonFace at index 36
//INFO : 	...the PolygonFace at index 27
//INFO : PolygonFace[2] at index PolygonFace is next to...
//INFO : 	...the PolygonFace at index 27
//INFO : 	...the PolygonFace at index 36
//INFO : 	...the PolygonFace at index 43
//INFO : 	...the PolygonFace at index 34
//INFO : PolygonFace[3] at index PolygonFace is next to...
//INFO : 	...the PolygonFace at index 28
//INFO : 	...the PolygonFace at index 37
//INFO : 	...the PolygonFace at index 44
//INFO : 	...the PolygonFace at index 35

3. Python Example

#
# This example demonstrates how to determine which polygons 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 polygons on it
disc = app.ActiveSceneRoot.AddGeometry( "Sphere", "MeshSurface" )
app.Selection.Clear()
app.Selection.SetAsText( disc.Name + ".poly[20,3,47,0,16,34,22]" );
# 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 a 
# PolygonFaceCollection)
selected = app.Selection(0).SubComponent.ComponentCollection
for sel in selected :
	app.LogMessage( "poly[%s] is selected." % (sel.Index) )
# Expected results:
#INFO : poly[20] is selected.
#INFO : poly[3] is selected.
#INFO : poly[47] is selected.
#INFO : poly[0] is selected.
#INFO : poly[16] is selected.
#INFO : poly[34] is selected.
#INFO : poly[22] is selected.