Multiple conditions for search sets

Multiple conditions for search sets

Anonymous
Not applicable
3,562 Views
6 Replies
Message 1 of 7

Multiple conditions for search sets

Anonymous
Not applicable

Hi everyone,

is there a possibility to add more than one condition to a search sets via a plugin?

2019-07-23 10_13_54-C03 bis C09.dwg - Autodesk Navisworks Manage 2018.png

Right now I only can add one condition with the following code:

 public SavedItem create_search(string categorydisplayname, string propertydisplayname, string variantdata, string searchsetsname)
        {
            Search s = new Search();
            SearchCondition sc = SearchCondition.HasPropertyByDisplayName(categorydisplayname, propertydisplayname);
            s.SearchConditions.Add(sc.EqualValue(VariantData.FromDisplayString(variantdata)));

            ////set the selection to everything

            s.Selection.SelectAll();
            s.Locations = SearchLocations.DescendantsAndSelf;
            SavedItem newItem = new SelectionSet(s);
            newItem.DisplayName = searchsetsname;

            return newItem;
        }

Can anyone explain me how to add multiple conditions?

(Just for explanations: I will need to add the search set to a FolderItem, that's why I'm using SavedItem, but if there is a better solution, please explain me.)

Thanks in advance.

Regards 

Ramona

Accepted solutions (1)
3,563 Views
6 Replies
Replies (6)
Message 2 of 7

Anonymous
Not applicable

Hi,

 

Yes, you just need to add an other condition (or more) to the search you created. For example :

 

Search s = new Search();
SearchCondition sc = SearchCondition.HasPropertyByDisplayName(categorydisplayname, propertydisplayname); // first SearchCondition
s.SearchConditions.Add(sc.EqualValue(VariantData.FromDisplayString(variantdata)));  // first SearchCondition added to the search conditions

SearchCondition sc2 = SearchCondition.HasPropertyByDisplayName(categorydisplayname, propertydisplayname); // second SearchCondition
s.SearchConditions.Add(sc2.EqualValue(VariantData.FromDisplayString(variantdata2))); // second SearchCondition added to the search conditions

etc ...


the rest of the code is the same.

 

Note : all these conditions are evaluated with an 'and' logic (cond1 & cond2 needs to be true to have a result) so in the above example variantdata needs to be the same as variantdata2 to have a result so you have to modify the second condition to your desired one (I used the same condition for demonstration purposes) 

 

Best Regards.

0 Likes
Message 3 of 7

Anonymous
Not applicable

@Anonymous Thanks for your response. Do I need to create a new variable? or can I just do it in a for loop?

Search s = new Search();
foreach(condition)
{
SearchCondition sc = SearchCondition.HasPropertyByDisplayName(categorydisplayname, propertydisplayname); // first SearchCondition
s.SearchConditions.Add(sc.EqualValue(VariantData.FromDisplayString(variantdata)));  // first SearchCondition added to the search conditions
}
0 Likes
Message 4 of 7

Anonymous
Not applicable

Hi @Anonymous  , it's me the user @Anonymous (sorry posted with the wrong profile)

 

That is possible but the code depends on what you want to do and what is your data input.

 

Basically, the 'Search s = new Search();' variable needs to be the same and the ' SearchCondition sc ' variable can be recreated or updated in your for loop.

0 Likes
Message 5 of 7

ulski1
Collaborator
Collaborator
Hi,
You use SearchConditions.Add
See the article Xiaodong Liang wrote in 2012
https://adndevblog.typepad.com/aec/2012/07/use-search-api.html
or see the reply I wrote in 2015
https://forums.autodesk.com/t5/navisworks-api/searchcondition-is-not-working/td-p/5818301

br
Ulrik
0 Likes
Message 6 of 7

Anonymous
Not applicable

@ulski1  thanks for your response.

For you as information:

As input I get strings with 2 conditions like shown above in the picture.
As output I would like to save a SearchSet with 2 conditions in a subfolder.

So right now I do have the problem, that I can only save a searchset with one condition.

As suggested I tried to do it like the tutorial below said with groups. But can I do it as followed?
https://adndevblog.typepad.com/aec/2012/07/use-search-api.html

 

Search s = new Search();
s.Selection.SelectAll();
//SearchCondition1 of group1:the item is required SearchCondition oGroup1_SC1 =SearchCondition.HasPropertyByDisplayName("Item", "Required"); oGroup1_SC1 = oGroup1_SC1.EqualValue(VariantData.FromBoolean(true)); //SearchCondition2 of group1:the item's DWG handle is 16C17 SearchCondition oGroup1_SC2 =SearchCondition.HasPropertyByDisplayName("Entity Handle", "Value"); oGroup1_SC2 = oGroup1_SC2.EqualValue(VariantData.FromDisplayString("16C17"));

 

System.Collections.Generic.List<SearchCondition> oG1 =new System.Collections.Generic.List<SearchCondition>();
oG1.Add(oGroup1_SC1);
oG1.Add(oGroup1_SC2);
s.SearchConditions.AddGroup(oG1);

s.Selection.SelectAll();
s.Locations = SearchLocations.DescendantsAndSelf;
SavedItem newItem = new SelectionSet(s);   
0 Likes
Message 7 of 7

ulski1
Collaborator
Collaborator
Accepted solution
It is always difficult to spot if you are missing something. You can set the display name of the search set like so newItem.DisplayName = ;
For more about selection sets see these articles
https://adndevblog.typepad.com/aec/2012/08/add-search-selectionset-in-net.html
https://adndevblog.typepad.com/aec/2015/07/update-selectionset.html