Softimage SDK Programmer's Guide > Plug-in Development > Selection > Finding Out What's Currently Selected >

# Accessing the List of Selected Components via the Object Model

- When components are selected, the Selection.Item property returns a CollectionItem object which you can use to get the SubComponent object via the CollectionItem.SubComponent property. From there, the SubComponent.ComponentCollection property returns one of the geometry-specific component collections (VertexCollection, ControlPointCollection, EdgeCollection, etc.) containing the selected components:

    // C# -- assuming sampled points are selected
    CXSIApplication app = new CXSIApplication();
    CollectionItem collitem = (CollectionItem)app.Selection[0];
    SubComponent subcmp = (SubComponent)collitem.SubComponent;
    SampleCollection smplcoll = (SampleCollection)subcmp.ComponentCollection;
    app.LogMessage("There are " + smplcoll.Count.ToString()
    	+ " selected samples.", siSeverity.siInfo);
    foreach (Sample smpl in smplcoll)
    {
    	app.LogMessage("Current sample[" + smpl.Index.ToString()
    		+ "] (prev:[" + smpl.Navigate(siNavigateComponentType.siPreviousComponent).Index.ToString()
    		+ "]; next:[" + smpl.Navigate(siNavigateComponentType.siNextComponent).Index.ToString()
    		+ "])", siSeverity.siInfo);
    }

    // JScript -- assuming control points are selected
    var subcmp = Selection(0).SubComponent;
    var ctrlpts = subcmp.ComponentCollection;
    for( var i=0; i<ctrlpts.Count; i++ )
    {
    	LogMessage( "Position of ctrlpt[" + ctrlpts(i).Index + "]: "
    		+ ctrlpts(i).X + ","
    		+ ctrlpts(i).Y + ","
    		+ ctrlpts(i).Z );
    }

    ' VBScript -- assuming vertices are selected
    set subcmp = Selection(0).SubComponent
    for each vtx in subcmp.ComponentCollection
    	LogMessage vtx.Index & " has " & vtx.Nodes.Count & " polygon nodes"
    next

    # Python -- assuming edges are selected
    subcmp = Application.Selection(0).SubComponent
    for edg in subcmp.ComponentCollection :
    	Application.LogMessage( "edge[%s] is hard: %s" % (edg.Index,edg.IsHard) )

    # Perl -- assuming Nurbs subsurfaces are selected
    my $subcmp = $Application->Selection(0)->SubComponent;
    my $coll = $subcmp->ComponentCollection;
    for ( my $i=0; $i<$coll->Count; $i++ ) {
    	$Application->LogMessage( $coll->Item($i)->TrimCount );
    }

Related Scripting Commands

- GetValue (used with "SelectionList")

- PickElement, PickObject

- SelectFilter, SelectEdgeFilter, SelectObjectFilter, SelectPolygonFilter, SelectSampledPointFilter, SelectVertexFilter

- SetEdgeSelectionFilter, SetPointSelectionFilter, SetPolygonSelectionFilter, SetSampleSelectionFilter