|
![]() |
SelectionSet (Sets in the Navisworks GUI) allow selections of ModelItem to be grouped.
These selection sets are displayed in a hierachy determined by the user, but through the API they can now be created, accessed and removed programmatically.
Classes involved
Several classes are involved to represent SelectionSets, these are:
-
SavedItem
- The abstract base class of all the following section set related classes
- FolderItem
- SelectionSet
To access the SelectionSets in a Document there is the property SelectionSets which is an instance of DocumentSelectionSets. This is a Autodesk.Navisworks.Api.DocumentParts and so follows the normal structure.
DocumentSelectionSets..::..Value provides the entry point to the selection sets structure and DocumentSelectionSets..::..RootItem provides a convenient read-only equivelent of a parent FolderItem of the same selection sets. This FolderItem however cannot be removed as it is just a placeholder to access the entries in DocumentSelectionSets..::..Value.
Accessing, creating and removing a Document's SelectionSet
In the following example we use recursion to iterate through the selection sets contained in the currectly active Document.

using System.Text; using Autodesk.Navisworks.Api.Controls; static public string WriteSelectionSetContent(SavedItem item, string label, string lineText) { //set the output string output = lineText + "+ " + label + "\n"; //See if this SavedItem is a GroupItem if (item.IsGroup) { //Indent the lines below this item lineText += " "; //iterate the children and output foreach (SavedItem childItem in ((GroupItem)item).Children) { output += WriteSelectionSetContent(childItem, childItem.DisplayName, lineText); } } //return the node information return output; } /// <summary> /// Outputs to a message box the structure of the selection sets /// </summary> static public void ListSelectionSets() { //build output string for display string output = WriteSelectionSetContent( Autodesk.Navisworks.Api.Application.ActiveDocument.SelectionSets.RootItem, Autodesk.Navisworks.Api.Application.ActiveDocument.Title, ""); //output in a message box MessageBox.Show(output); }
Selection Sets can be removed from the list of sets by calling one the methods of Remove.
Similarly they can be created using one of the various SelectionSet constructors or CopyFrom methods.