Navisworks API

Reply
Contributor
jordanmarr
Posts: 25
Registered: ‎10-14-2011
Message 1 of 3 (503 Views)
Accepted Solution

Search with "OR"

503 Views, 2 Replies
11-21-2011 07:04 AM

I have a Search with multiple SearchCondition objects added.  By default, conditions added create an "AND" style search.

Is there a way to do an "OR" style search?


More specifically, I have a list of element ids, and I want to know if it is possible to search for them all at once.

 

If not, then I suppose I could create a speparate search for each element.

 

 

Hi,

 

I assume you are using .NET API. This needs SearchCondition group. It is "AND” within one group. It is "OR"  among groups.  The code below is tested with the SDK sample model:  gatehouse.nwd.

 

//Create a new search

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"));

//SearchCondition1 of group2: the item is NOT required

SearchCondition oGroup2_SC1= SearchCondition.HasPropertyByDisplayName("Item", "Required");

oGroup2_SC1 = oGroup2_SC1.EqualValue(VariantData.FromBoolean(false));

//SearchCondition2 of group2: the item's DWG handle is 17C2E

SearchCondition oGroup2_SC2 = SearchCondition.HasPropertyByDisplayName("Entity Handle", "Value");

oGroup2_SC2 = oGroup2_SC2.EqualValue(VariantData.FromDisplayString("17C2E"));

//create group1

System.Collections.Generic.List<SearchCondition> oG1 = new System.Collections.Generic.List<SearchCondition>();

oG1.Add(oGroup1_SC1);

oG1.Add(oGroup1_SC2);

//create group2

System.Collections.Generic.List<SearchCondition> oG2 = new System.Collections.Generic.List<SearchCondition>();

oG2.Add(oGroup2_SC1);

oG2.Add(oGroup2_SC2);

// add groups to SearchConditions

s.SearchConditions.AddGroup(oG1);

s.SearchConditions.AddGroup(oG2);

//highlight the items

ModelItemCollection searchResults = s.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument

 

Regards,

Xiaodong Liang

Developer Technical Services

ADN Support Specialist
xiaodong.liang
Posts: 1,305
Registered: ‎06-12-2011
Message 2 of 3 (480 Views)

Re: Search with "OR"

11-23-2011 10:48 PM in reply to: jordanmarr

Hi,

 

I assume you are using .NET API. This needs SearchCondition group. It is "AND” within one group. It is "OR"  among groups.  The code below is tested with the SDK sample model:  gatehouse.nwd.

 

//Create a new search

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"));

//SearchCondition1 of group2: the item is NOT required

SearchCondition oGroup2_SC1= SearchCondition.HasPropertyByDisplayName("Item", "Required");

oGroup2_SC1 = oGroup2_SC1.EqualValue(VariantData.FromBoolean(false));

//SearchCondition2 of group2: the item's DWG handle is 17C2E

SearchCondition oGroup2_SC2 = SearchCondition.HasPropertyByDisplayName("Entity Handle", "Value");

oGroup2_SC2 = oGroup2_SC2.EqualValue(VariantData.FromDisplayString("17C2E"));

//create group1

System.Collections.Generic.List<SearchCondition> oG1 = new System.Collections.Generic.List<SearchCondition>();

oG1.Add(oGroup1_SC1);

oG1.Add(oGroup1_SC2);

//create group2

System.Collections.Generic.List<SearchCondition> oG2 = new System.Collections.Generic.List<SearchCondition>();

oG2.Add(oGroup2_SC1);

oG2.Add(oGroup2_SC2);

// add groups to SearchConditions

s.SearchConditions.AddGroup(oG1);

s.SearchConditions.AddGroup(oG2);

//highlight the items

ModelItemCollection searchResults = s.FindAll(Autodesk.Navisworks.Api.Application.ActiveDocument

 

Regards,

Xiaodong Liang

Developer Technical Services



Xiaodong Liang
Developer Technical Services
Autodesk Developer Network

Contributor
jordanmarr
Posts: 25
Registered: ‎10-14-2011
Message 3 of 3 (465 Views)

Re: Search with "OR"

11-30-2011 01:05 PM in reply to: xiaodong.liang

Great!  Thank you very much.

 

Jordan

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!