Issue
I create two find conditions and add into find spec. So it means condition1 "AND" with condition2. How can I make condition1 "OR" with condition2? "(A or B)"
Solution
InwOpFindCondition has a property [StartGroup] that can be used to do this:
"Set to FALSE to start new group of conditions. Conditions within groups are ANDed together, groups are ORed together."
The sample code below is tested with the SDK sample in <Navisworks Manage 2013>api\COM\examples\ActiveX\ActiveXFindExample. It searches the objects whose entity handle is “16C17” or “377” within the sample model <Navisworks Manage 2013>\api\COM\examples\gatehouse.nwd.
using NavisworksIntegratedAPI10;
private void findOr()
{
// Create the various components of the
// search using object factories
InwOpFind find =
m_state.ObjectFactory(nwEObjectType.eObjectType_nwOpFind)
as InwOpFind;
InwOpFindSpec findSpec =
m_state.ObjectFactory(nwEObjectType.eObjectType_nwOpFindSpec)
as InwOpFindSpec;
// create first find condition
InwOpFindCondition findCondition1 =
m_state.ObjectFactory(nwEObjectType.eObjectType_nwOpFindCondition)
as InwOpFindCondition;
// create second find condition
InwOpFindCondition findCondition2 =
m_state.ObjectFactory(nwEObjectType.eObjectType_nwOpFindCondition)
as InwOpFindCondition;
//configure the first find condition
findCondition1.StartGroup = false;
findCondition1.Condition = nwEFindCondition.eFind_EQUAL;
findCondition1.SetAttributeNames("", "Entity Handle");
findCondition1.SetPropertyNames("", "Value");
findCondition1.value = "16C17";
//configure the second find condition
findCondition2.StartGroup = false;
findCondition2.Condition = nwEFindCondition.eFind_EQUAL;
findCondition2.SetAttributeNames("", "Entity Handle");
findCondition2.SetPropertyNames("", "Value");
findCondition2.value = "377";
//select all
findSpec.selection = null;
//add first find condition
findSpec.Conditions().Add(findCondition1);
//add second find condition
findSpec.Conditions().Add(findCondition2);
find.FindSpec = findSpec;
bool bFirst=true;
object match_data = Type.Missing;
bool finished = false;
// Populate the results table with the found items.
do
{
InwOaPath path =
find.Find(bFirst, ref match_data);
bFirst = false;
if (path != null)
{
InwOaNode node =
path.Nodes().Last() as NavisworksIntegratedAPI10.InwOaNode;
// print some info of the node
MessageBox.Show(node.ClassName + " " +
node.ClassUserName + " " + node.ObjectName);
}
else
finished = true;
}while(finished != true);
}
}