Can I Create Search Set using API?

Can I Create Search Set using API?

chan_baek
Enthusiast Enthusiast
286 Views
3 Replies
Message 1 of 4

Can I Create Search Set using API?

chan_baek
Enthusiast
Enthusiast

Can I Create Search Set using API?

0 Likes
Accepted solutions (1)
287 Views
3 Replies
Replies (3)
Message 2 of 4

naveen.kumar.t
Autodesk Support
Autodesk Support
Accepted solution

Hi @chan_baek ,

 

Yes, it is possible. Please take a look at the code below.

Search s = new Search();
SearchCondition sc = SearchCondition.HasPropertyByDisplayName("Item","Name");
s.SearchConditions.Add(sc.EqualValue(VariantData.FromDisplayString("Basic Wall")));
s.Selection.SelectAll();
s.Locations = SearchLocations.DescendantsAndSelf;

SavedItem newItem = new SelectionSet(s);
newItem.DisplayName = "MySearchSetName"; 

Autodesk.Navisworks.Api.Application.ActiveDocument.SelectionSets.InsertCopy(0, newItem);

Naveen Kumar T
Developer Technical Services
Autodesk Developer Network

Message 3 of 4

chan_baek
Enthusiast
Enthusiast

@naveen.kumar.t Thanks for helping. Then, Can I Create folder too?

0 Likes
Message 4 of 4

chan_baek
Enthusiast
Enthusiast

I solved it. Thank you.

Search s = new Search();
SearchCondition sc = SearchCondition.HasPropertyByDisplayName("Item", "Name");
s.SearchConditions.Add(sc.EqualValue(VariantData.FromDisplayString("Basic Wall")));
s.Selection.SelectAll();
s.Locations = SearchLocations.DescendantsAndSelf;

SavedItem newItem = new SelectionSet(s) { DisplayName = "MySearchSetName" };

// 폴더 생성
SavedItem folder = new FolderItem { DisplayName = "aaaa" };

// 폴더를 SelectionSets 루트에 추가
NavisApp.ActiveDocument.SelectionSets.InsertCopy(0, folder);
var doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
var selectionSets = doc.SelectionSets; // DocumentSelectionSets
var rootFolder = selectionSets.RootItem; // SelectionSets 트리의 루트 SavedItem
SavedItem savedFolder = null;
foreach (SavedItem item in rootFolder.Children)
{
if (item is FolderItem folderItem && folderItem.DisplayName == "aaaa")
{
savedFolder = folderItem;
break;
}
}


// 폴더의 IndexPath 가져오기
//Collection<int> index = NavisApp.ActiveDocument.SelectionSets.CreateIndexPath(savedFolder);

// 폴더 안에 SearchSet 삽입 (폴더의 IndexPath를 기준으로 Insert)
NavisApp.ActiveDocument.SelectionSets.InsertCopy((GroupItem)savedFolder, 0, newItem);