Saturday Snippet: Selection, LAST, and SubComponents


Selection.Clear();
var oCube = ActiveSceneRoot.AddGeometry( "Cube", "MeshSurface" );

var n = oCube.ActivePrimitive.Geometry.Points.Count

//SelectGeometryComponents(oCube.Name + ".pnt[1,3,5,LAST]");
Selection.Add( oCube.ActivePrimitive.Geometry.Points(1) );
Selection.Add( oCube.ActivePrimitive.Geometry.Points(3) );
Selection.Add( oCube.ActivePrimitive.Geometry.Points(5) );
Selection.Add( oCube.ActivePrimitive.Geometry.Points(n-1) );

var sel = XSIFactory.CreateActiveXObject("XSI.Collection");           
sel.AddItems(Selection);                  

LogMessage( sel.Count );
// INFO : 1

LogMessage( ClassName( sel(0) ) );
// INFO : CollectionItem

LogMessage( sel(0).Value );
// INFO : cube.pnt[1,3,5,LAST]

n = sel(0).SubComponent.ComponentCollection.Count
LogMessage( sel(0).SubComponent.ComponentCollection(n-1).Index );
// INFO : 7

LogMessage( VBArray( sel(0).SubComponent.ElementArray ).toArray()[n-1] );
// INFO : 7

//LogMessage( sel(0).SubComponent.ComponentCollection );
LogMessage( VBArray( sel(0).SubComponent.ElementArray ).toArray() );

And don’t do this. You’ll have to restart Softimage to get selection working again.

var sel = XSIFactory.CreateActiveXObject("XSI.Collection");           
sel.AddItems(Selection);                  
sel(0).Value = "cube.pnt[7]";

Saturday Snippet – XSICollections and CollectionItems


When you stick something, like say a Vertex, into an XSICollection, you get a CollectionItem. But you can get back to the Vertex if you know how (via the SubComponent
).

si = Application
log = si.LogMessage
sisel = si.Selection
import win32com.client

oColl = win32com.client.Dispatch( "XSI.Collection" )
o = sisel(0)

print si.ClassName( o.ActivePrimitive.Geometry.Vertices(0) )
# Vertex

#oColl.Add( o.ActivePrimitive.Geometry.Vertices(0) )
oColl.AddItems( o.ActivePrimitive.Geometry.Vertices )
print si.ClassName( oColl(0) )
# CollectionItem

print si.ClassName( oColl(0).SubComponent.ComponentCollection(0) )
# Vertex

a = o.ActivePrimitive.Geometry.Vertices(0)
b = oColl(0).SubComponent.ComponentCollection(0)
print a.IsEqualTo(b)
# True
print b.IsEqualTo(a)
# True