The construction method of SelectionSet provides the way to add a search object. Thus you can create the selectionset with the search. Following is a small demo code.
void AddSearchSelectionSetByNet() { // create a search and conditions Search s = new Search(); SearchCondition sc = SearchCondition.HasPropertyByDisplayName("Element", "Category"); s.SearchConditions.Add( sc.EqualValue(VariantData.FromDisplayString("Walls"))); //set the selection to everything s.Selection.SelectAll(); s.Locations = SearchLocations.DescendantsAndSelf; // create a selectionset with the search condition SavedItem newItem = new SelectionSet(s); newItem.DisplayName = "My Walls"; // add this selection set to selection set collection Autodesk.Navisworks.Api.Application.ActiveDocument. SelectionSets.InsertCopy(0, newItem); }

Leave a Reply