The Selection or Selection object/class is a kind of a specialized collection. Each selected object is a member and can be accessed via enumerating or using the Selection.Item or Selection::GetItem property:
// C++ API
Selection sel( Application().GetSelection() );
for( LONG i=0; i<sel.GetCount(); i++ )
{
SIObject obj( sel[i] );
Application().LogMessage( obj.GetName() );
}
SIObject objByIndex( sel.GetItem(0) ); // Access by index
SIObject objByName( sel.GetItem(L"grid") ); // Access by name
// C# (object model)
CXSIApplication app = new CXSIApplication();
foreach (CollectionItem itm in app.Selection)
{
app.LogMessage(itm.Name, siSeverity.siInfo);
}
SIObject objByIndex = (SIObject)app.Selection[0]; // Access by index
SIObject objByName = (SIObject)app.Selection["cone"]; // Access by name
// JScript
var e = new Enumerator( Selection );
for( ; !e.atEnd(); !e.moveNext() )
{
var obj = e.item();
LogMessage( obj );
}
var objByIndex = Selection(0); // Access by index
var objByName = Selection("grid"); // Access by name
' VBScript
foreach obj in Selection
LogMessage obj
next
set objByIndex = Selection(0);' Access by index
set objByName = Selection("grid");' Access by name
# Python
for obj in Application.Selection :
Application.LogMessage( obj.Name )
objByIndex = Application.Selection(0) # Access by index
objByName = Application.Selection("grid") # Access by name
Except where otherwise noted, this work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License