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 script commands (for example, see the SelectObj, AddToSelection, RemoveFromSelection, ToggleSelection, and DeselectAll, commands etc.).
using namespace XSI; Application app; Model root = app.GetActiveSceneRoot(); // creates some objects and adds them to the selection list X3DObject myCube; root.AddGeometry( L"Cube", L"MeshSurface", L"myCube", myCube ); X3DObject myGrid; root.AddGeometry( L"Grid", L"NurbsSurface", L"myGrid", myGrid ); X3DObject myCylinder; root.AddGeometry( L"Cylinder", L"MeshSurface", L"myCylinder", myCylinder ); Property myProp; myCylinder.AddProperty(L"Display Property", false, L"MyDisplayProp", myProp); Selection selection( app.GetSelection() ); selection.Add( myCube ); selection.Add( myGrid ); selection.Add( myProp ); // iterate over the selection LONG lCount = selection.GetCount(); app.LogMessage( L"Selection count: " + CValue(lCount).GetAsText() ); for (LONG i=0; i<lCount; i++ ) { SIObject obj(selection[i]); app.LogMessage( L"Selection " + CValue(i).GetAsText() + L"= " + obj.GetName() ); } // enumerate all polygon meshes CRefArray array(selection.GetArray()); CRefArray meshRefArray; array.Filter(siPolyMeshType, CStringArray(), L"", meshRefArray ); lCount = meshRefArray.GetCount(); for (i=0; i<lCount; i++ ) { SIObject obj(meshRefArray[i]); app.LogMessage( L"Mesh "+CValue(i).GetAsText()+ L"= "+obj.GetName() ); } // find the selected display property CRef propRef; array.Find( siDisplayType, propRef ); SIObject obj(propRef); app.LogMessage( L"Display Property = " + obj.GetName() );
#include <xsi_selection.h>
Public Member Functions |
|
Selection () | |
~Selection () | |
Selection (const CRef &in_ref) | |
Selection (const Selection &in_obj) | |
bool | IsA (siClassID in_ClassID) const |
siClassID | GetClassID () const |
Selection & | operator= (const Selection &in_obj) |
Selection & | operator= (const CRef &in_ref) |
CRef | operator[] (LONG in_index) |
CRef | GetItem (LONG in_index) const |
CRef | GetItem (const CString &in_name) const |
CStatus | Add (const CRef &in_object, siSelectMode in_selType=siSelectDefault) |
CStatus | Remove (const CRef &in_object, siSelectMode in_selType=siSelectDefault) |
CStatus | Clear () |
LONG | GetCount () const |
CRefArray | GetArray () |
CStatus | SetAsText (const CString &in_str) |
CString | GetAsText () |
Filter | GetFilter () const |
Selection | ( | ) |
Default constructor.
~Selection | ( | ) |
Default destructor.
bool IsA | ( | siClassID | in_ClassID | ) | const [virtual] |
Returns true if a given class type is compatible with this API class.
in_ClassID | class type. |
Reimplemented from CBase.
siClassID GetClassID | ( | ) | const [virtual] |
Creates an object from another object. The new object is set to empty if the input object is not compatible.
in_obj | constant class object. |
Creates an object from a reference object. The new object is set to empty if the input reference object is not compatible.
in_ref | constant class object. |
CRef operator[] | ( | LONG | in_index | ) |
Accesses elements at a given index.
in_index | CRef object |
CRef GetItem | ( | LONG | in_index | ) | const |
Returns a CRef object contained in the list given an index number.
in_index | A number index |
Returns a CRef object contained in the list given an object string name.
in_name | The name of an object to retrieve. |
CStatus Add | ( | const CRef & | in_object, |
siSelectMode | in_selType =
siSelectDefault |
||
) |
Adds a reference to an object to the selection list.
in_object | A reference to the object to add. |
in_selType | Specifies how the object is selected in hierarchy. |
CStatus Remove | ( | const CRef & | in_object, |
siSelectMode | in_selType =
siSelectDefault |
||
) |
Removes a item from the selection list.
in_object | A reference to object to remove. |
in_selType | Specifies how the object is selected in hierarchy (node, branch, tree, model) |
CStatus Clear | ( | ) |
LONG GetCount | ( | ) | const |
Returns the number of items in the Selection
CRefArray GetArray | ( | ) |
Returns a CRefArray containing the selected objects.
Sets the selection by parsing a given string.
in_str | Text string to parse. The string list is comma-separated. You
may use wildcards in the string to match many object for example
light* |
using namespace XSI; Application app; Model root = app.GetActiveSceneRoot(); X3DObject myCube; root.AddGeometry( L"Cube", L"MeshSurface", L"myCube", myCube ); X3DObject myGrid; root.AddGeometry( L"Grid", L"NurbsSurface", L"myGrid", myGrid ); X3DObject myCylinder; root.AddGeometry( L"Cylinder", L"MeshSurface", L"myCylinder", myCylinder ); Selection sel = app.GetSelection(); CString str; str = L"myCube"; str += L","; str += L"myGrid"; str += L","; str += L"myCylinder"; sel.SetAsText( str ); LONG lCount = sel.GetCount(); app.LogMessage( L"Selection count: " + CValue(lCount).GetAsText() ); //'INFO : "Selection count: 3" for (LONG i=0; i<lCount; i++ ) { SIObject obj(sel[i]); app.LogMessage( L"Selection " + CValue(i).GetAsText() + L"= " + obj.GetFullName() ); } //'INFO : "Selection 0= myCube" //'INFO : "Selection 1= myGrid" //'INFO : "Selection 2= myCylinder"
CString GetAsText | ( | ) |
Returns the contents of the selection as a readable string.
using namespace XSI; Application app; Model root = app.GetActiveSceneRoot(); X3DObject myCube; root.AddGeometry( L"Cube", L"MeshSurface", L"myCube", myCube ); X3DObject myGrid; root.AddGeometry( L"Grid", L"NurbsSurface", L"myGrid", myGrid ); X3DObject myCylinder; root.AddGeometry( L"Cylinder", L"MeshSurface", L"myCylinder", myCylinder ); Selection sel = app.GetSelection(); sel.Add( myCube ); sel.Add( myGrid ); sel.Add( myCylinder ); CString strSel = sel.GetAsText(); app.LogMessage( L"Selection as text: " + strSel ); // 'INFO : "Selection as text: myCube,myGrid,myCylinder"
Filter GetFilter | ( | ) | const |
Returns the currently selected filter from the selection.
using namespace XSI; Application app; Selection sel = app.GetSelection(); Filter currentFilter = sel.GetFilter(); app.LogMessage( L"Selected filter: " + currentFilter.GetName() );