Public Member Functions
Selection Class Reference

## Detailed Description

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.).

Note:
  Selection provides access to its members through Selection::GetItem which returns a reference to the specified item. For example, whether you select the whole sphere or only a subcomponent (like an edge), you get a CRef.

Example:

            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>`

Inheritance diagram for Selection:
[legend]

List of all members.

## 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

## Constructor & Destructor Documentation

Selection | ( |  | ) |

Default constructor.

~Selection | ( |  | ) |

Default destructor.

Selection | ( | const CRef & | in_ref | ) |

Constructor.

Parameters:

  in_ref | constant reference object.

Selection | ( | const Selection & | in_obj | ) |

Copy constructor.

Parameters:

  in_obj | constant class object.

## Member Function Documentation

bool IsA | ( | siClassID | in_ClassID | ) | const`[virtual]`

Returns true if a given class type is compatible with this API class.

Parameters:

  in_ClassID | class type.

Returns:
  true if the class is compatible, false otherwise.

Reimplemented from CBase.

siClassID GetClassID | ( |  | ) | const`[virtual]`

Returns the type of the API class.

Returns:
  The class type.

Implements CBase.

Selection& operator= | ( | const Selection & | in_obj | ) |

Creates an object from another object. The new object is set to empty if the input object is not compatible.

Parameters:

  in_obj | constant class object.

Returns:
  The new Selection object.

Selection& operator= | ( | const CRef & | in_ref | ) |

Creates an object from a reference object. The new object is set to empty if the input reference object is not compatible.

Parameters:

  in_ref | constant class object.

Returns:
  The new Selection object.

CRef operator[] | ( | LONG | in_index | ) |

Accesses elements at a given index.

Parameters:

  in_index | CRef object

Returns:
  A new reference object.

CRef GetItem | ( | LONG | in_index | ) | const

Returns a CRef object contained in the list given an index number.

Parameters:

  in_index | A number index

Returns:
  A reference to the specified selection item.

CRef GetItem | ( | const CString & | in_name | ) | const

Returns a CRef object contained in the list given an object string name.

Parameters:

  in_name | The name of an object to retrieve.

Returns:
  A reference to the specified selection item.

CStatus Add | ( | const CRef & | in_object,
|  | siSelectMode | in_selType = `siSelectDefault`
| ) |  |

Adds a reference to an object to the selection list.

Parameters:

  in_object | A reference to the object to add.
  in_selType | Specifies how the object is selected in hierarchy.

Returns:
  CStatus::OK Success
  CStatus::Fail Failure

CStatus Remove | ( | const CRef & | in_object,
|  | siSelectMode | in_selType = `siSelectDefault`
| ) |  |

Removes a item from the selection list.

Parameters:

  in_object | A reference to object to remove.
  in_selType | Specifies how the object is selected in hierarchy (node, branch, tree, model)

Returns:
  CStatus::OK Success
  CStatus::Fail Failure

CStatus Clear | ( |  | ) |

Deselects everything.

Returns:
  CStatus::OK Success
  CStatus::Fail Failure

Reimplemented from CBase.

LONG GetCount | ( |  | ) | const

Returns the number of items in the Selection

Returns:
  Number of items

CRefArray GetArray | ( |  | ) |

Returns a CRefArray containing the selected objects.

Returns:
  The selection list.

CStatus SetAsText | ( | const CString & | in_str | ) |

Sets the selection by parsing a given string.

Parameters:

  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*`

Returns:
  CStatus::OK success
  CStatus::Fail The string is either badly formatted or contains unresolvable object names.

Example:
  Creates some objects and adds them to the selection list.

              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.

Returns:
  A readable string or an empty value if the string can't be expressed as a readable string.

Example:
  Creates some objects and adds them to the selection list

              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.

Returns:
  Current Filter object.

Since:
  4.0

Example:

            using namespace XSI;
            Application app;
            Selection sel = app.GetSelection();
            Filter currentFilter = sel.GetFilter();

            app.LogMessage( L"Selected filter: " +  currentFilter.GetName() );

The documentation for this class was generated from the following file:

- xsi_selection.h