Issue
I wanted to manipulate Selection Set in .NET. e.g. get some Selection Sets and add them to current selection.
Solution
From 2012, .NET API provides the object SelectionSet. Before 2012, the related objects are exposed in COM API.
The code below assumes you open the SDK sample gatehouse.nwd and want to highlight the first two selection sets in first level of the Selection Sets tree.
1) InwOpSelectionSet: Selection Set
2) InwSelectionSetFolder: folder of selection sets
3) state.SelectionSetsEx lists the selection sets and folders in first level of the Selection Sets tree
4) InwSelectionSetFolder. SelectionSets returns the selection sets and folders within this folder
// access selection set private void test() { ComApi.InwOpState10 state; state = ComApiBridge.ComApiBridge.State; // model items collection to store the // items of selection set ModelItemCollection modelItemCollectionIn = new ModelItemCollection(); // Selection Set Collection ComApi.InwSelectionSetExColl oSSExColl = state.SelectionSetsEx(); for (int i = 1; i 2) break; } else if (oSSExColl[
i] is ComApi.InwSelectionSetFolder) { //if this is folder. ComApi.InwSelectionSetFolder oSSFolder = (ComApi.InwSelectionSetFolder)oSSExColl[i]; // recurse the folder recurseFolderSS(oSSFolder); } else { } } //set the current selection // highlight the selection of the set Autodesk.Navisworks.Api.Application.ActiveDocument. CurrentSelection.CopyFrom(modelItemCollectionIn); } // recurse a selection set folder private void recurseFolderSS(ComApi.InwSelectionSetFolder folder) { ComApi.InwOpState10 state; state = ComApiBridge.ComApiBridge.State; ComApi.InwSelectionSetExColl oSSExColl = folder.SelectionSets(); for (int i = 1; i

Leave a Reply