How to get properties generated selection sets

How to get properties generated selection sets

Anonymous
Not applicable
2,883 Views
8 Replies
Message 1 of 9

How to get properties generated selection sets

Anonymous
Not applicable

Hi !

 

I know that we can obtain the list of saved selections sets like this :

 

 

            Document doc = Autodesk.Navisworks.Api.Application.ActiveDocument;
            foreach (SavedItem saveditem in doc.SelectionSets.Value)
            { 
                 //
            }

Is it possible to gets the generated selections sets by properties ? They are in Selection tree/Properties

 

 

image.png

0 Likes
2,884 Views
8 Replies
Replies (8)
Message 2 of 9

Anonymous
Not applicable

Hello sounds like you are trying to accomplish something similar to what I am looking for... Here is my post also.

 

https://forums.autodesk.com/t5/navisworks-api/search-sets-naming-from-a-property-value-for-each-valu...

 

But it appears that no one really responds to any posts in the API forum? I have not been getting any help myself on some posting I had in the past week. Lets see if any body can give us some direction. Good luck..

 

Jgarza

0 Likes
Message 3 of 9

Anonymous
Not applicable

The selectionset is different from the selectiontree.

If you want get all of the category and property You have to bring it from one model to another.

 

If the number of models is large, the speed is very slow.

 

foreach(ModelItem model in doc.Models[0].RootItem.DescendantsAndSelf)

{

          foreach(PropertyCategory category in model.PropertyCategories)

          {

                    string categoryName = category.DisplayName;

                    foreach(DataProperty property in category.Properties)

                    {

                                 string propertyName = property .DisplayName;

                    }

          }

}

Message 4 of 9

Anonymous
Not applicable

Thanks for the information, but where I am getting confused is so I still need the create a search condition like this one below? And how does your snip it filter out for the Property Category and the Category name? This is what I was starting with below..

#region Create and individual SearchSet For Tagged Instruments

Search cwTagInst = new Search();

SearchCondition cwTagInstc = SearchCondition.HasPropertyByDisplayName("CADWorx", "Tag");

cwTagInst.SearchConditions.Add(cwTagInstc.DisplayStringContains("FE-10215"));

//set the selection to everything

 cwTagInst.Selection.SelectAll();

cwTagInst.Locations = SearchLocations.DescendantsAndSelf;

SavedItem cwTagInstItem = new SelectionSet(cwTagInst);

cwTagInstItem.DisplayName = "All Tagged Inst";

  //add to the end

 oSets.AddCopy(cwTagInstItem);

#endregion

 

 

0 Likes
Message 5 of 9

Anonymous
Not applicable

I don`t understand what you want to do.

Do you want to know the search? or want to know the full property information?

0 Likes
Message 6 of 9

Anonymous
Not applicable

Its basically going to be a little of both, I assume. I am still learning about the api myself.

 

  1. I have to search the entire model for a specific property tag value just like the sample code shows in a previous post. (ie. FE*)
  2. and for each tag it finds I then to create a save search name to corresponds to the actual tag value after its found. (ie. FE-1000, FE-2015).
  3. Last I want a folder to be created that will store these search sets. (ie. folder name "FE's, and then list FE-1000, FE-2015 under the folder name and sort them) This will allow us to quickly find the items we are looking for instead of creating these saved search sets every time and to have consistent searches names and results.
  4. The ultimate goal is to call this plugin for use the same code in my automation process. To create these saved searches during the automation process, so when the nwf and nwd are generated they will be included already and users don't have to create any thing.

 

Message 7 of 9

Anonymous
Not applicable

There are two ways to utilize Search and ModelItem.
In this case, you must use SelectionSet


This is the sample code I used to create the SelectionSet.
You can put the SelectionSet in a FolderItem and add it to the root of the SelectionSet.

 

/// CreateSearchSet

Search s = new Search();

s.Selection.SelectAll();

search.Locations = SearchLoactions.DescendantsAndSelf;

SearchCondition sc = new SearchCondition(new NamedConstant("CategoryDisplayName"),

new NamedConstant("PropertyDisplayName"),

SearchConditionOptions.IgnoreNames,

SearchConditionComparison.Equal,

new VariantData("SearchName"));

 search.SearchConditions.AddGroup(sc);

SelectionSet ss = new SelectionSet(s);

ss.DisplayName = "SelectionSetName")

 

//CreateFolder

FolderItem fi = new FolderItem();

fi.DisplayName = "FolderName";

fi.Children.Add(ss);

 

//input SelectionSet

doc.SelectionSets.AddCopy(fi);

Message 8 of 9

Anonymous
Not applicable

Almost getting there...i don't see where to declare the search variable? i get the error "The name "search" does not exist in the current context." for the following 2 lines of code..

            search.Locations = SearchLocations.DescendantsAndSelf;

            search.SearchConditions.AddGroup(sc);

 

All the code...

#region 

Document oDoc = Autodesk.Navisworks.Api.Application.ActiveDocument;

/// CreateSearchSet

Search s = new Search();

s.Selection.SelectAll();

search.Locations = SearchLocations.DescendantsAndSelf;

SearchCondition sc = new SearchCondition(new NamedConstant("CADWorx"),
//SearchCondition sc = new SearchCondition(new NamedConstant("CategoryDisplayName"),

new NamedConstant("Tag"),
//new NamedConstant("PropertyDisplayName"),

SearchConditionOptions.IgnoreNames,

SearchConditionComparison.Equal,
//SearchConditionComparison.Equal,

new VariantData("Test123"));

search.SearchConditions.AddGroup(sc);

SelectionSet ss = new SelectionSet(s);

//ss.DisplayName = "SelectionSetName")
ss.DisplayName = ("Test");

//CreateFolder

FolderItem fi = new FolderItem();

fi.DisplayName = "FE's";

fi.Children.Add(ss);


//input SelectionSet

oDoc.SelectionSets.AddCopy(fi);

#endregion

 

 

0 Likes
Message 9 of 9

Anonymous
Not applicable

line 2 is a typing error

search.Locations -> s.Locations

0 Likes