Object Hierarchy | Related C++ Class: Selection
v1.0
The selection object represents the global selection for the
application. The user can change the global selection in the views,
explorer, MCA (selection sub-panel in the main control panel), and
through scripting (for example, see SelectObj, AddToSelection, RemoveFromSelection,
ToggleSelection,
DeselectAll, etc.).
Note: Selection provides access to its members through the Selection.Item property. Depending on
what is selected, the Selection.Item property returns either the
object or a CollectionItem. For
example, if you select the whole sphere, the Selection.Item
property returns the sphere as an X3DObject; however, if you select only a
subcomponent (like an edge), it returns the edge as a CollectionItem.
'This example demonstrates how a script can find the selected vertices 'in a selection of multiple objects. 'Set up a little scenario coneName = CreatePrim( "Cone", "MeshSurface" ) sphereName = CreatePrim("Sphere", "MeshSurface" ) DeselectAll AddToSelection coneName &".pnt[4,7,10]", , True AddToSelection sphereName &".pnt[1,2,3]", , True 'Now iterate through the selection using the OM selection object set oSelection = Application.Selection for i = 0 to (oSelection.Count - 1) if ( oSelection(i).Type = "pntSubComponent" ) then logmessage "Found the following selected vertices on " & oSelection(i).Subcomponent.Parent3DObject.Name 'Selection of points set subComponent = oSelection(i).SubComponent selectedIndices = subComponent.ElementArray for j = 0 to Ubound( selectedIndices, 1 ) logmessage selectedIndices(j) next else logmessage "Nothing to do with " & oSelection(i).Name & "Type (" & oSelection(i).Type & ")" end if next 'Output of the above script is: '"Found the following selected vertices on cone" '"4" '"7" '"10" '"Found the following selected vertices on sphere" '"1" '"2" '"3" |
' ' This example shows how to save the current selection into ' an XSICollection object. This can be very useful if you want ' to remember what objects were selected before running ' commands that might change the selection ' ' Note: Although this example sets up its own selection, you ' could remove the SETUP section and run this example with ' your own selection instead. ' ' SETUP NewScene , false set arc = CreatePrim( "Arc", "NurbsCurve" ) set disc = CreatePrim( "Disc", "MeshSurface" ) CreatePrim "Cylinder", "MeshSurface" set oSelection = Application.Selection oSelection.Clear oSelection.Add arc oSelection.Add disc ' MAIN Application.LogMessage "Current selection: " & oSelection.GetAsText() strSelection = oSelection.GetAsText() set oColl = CreateObject( "XSI.Collection" ) oColl.SetAsText strSelection Application.LogMessage "Contents of XSICollection: " & oColl.GetAsText ' RESULTS 'INFO : Current selection: arc,disc 'INFO : Contents of XSICollection: arc,disc |