Navisworks Clash allows the types of SelectionA and SelectionB to be set by Model Items from the standard or compact model tree, by properties, or by selection set.
From an API perspective, SelectionA and SelectionB are of type ClashSelection, whose Selection property can hold an explicit selection or a selection source. The model tree items are explicit selection. The properties or selection set is a selection source.
Currently, Navisworks API supports setting the Selection from the model tree or from a selection set.
The below are some demos. Given a clash test
var doc = Application.MainDocument;
//build clash test
DocumentClash clashDoc = doc.GetClash();
ClashTest clashTest = new ClashTest
{
DisplayName = "MyTest",
Tolerance = 1.0
};
To set selection with model items, build ModelItemCollection with items, and set Selection with this ModelItemCollection. If the item is root item of model or child items of root, the collection will map to compact tree. any of them is other decedent item, the collection will map to standard tree. e.g. the code below is to set root items as SelectionA and SelectionB.
ModelItemCollection theCollection = new ModelItemCollection();
theCollection.Add(doc.Models[0].RootItem);
clashTest.SelectionA.Selection.CopyFrom(theCollection);
clashTest.SelectionB.Selection.CopyFrom(theCollection);
The selections will be presented in UI:

If with the code below, the SelectionA will be item of compact tree. The SelectionB will be item of standard tree.
ModelItemCollection theCollection = new ModelItemCollection();
theCollection.Add(doc.Models[0].RootItem.Descendants.First());
theCollection.Add(doc.Models[0].RootItem.Descendants.Last());
clashTest.SelectionA.Selection.CopyFrom(theCollection);
clashTest.SelectionB.Selection.CopyFrom(theCollection);

In such situation, SelectionA(or B).Selection attribute HasExplicitSelection=true.
It is tricky to set selection with SelectionSet. As mentioned, it is a selection source. The first step is to create selection source with the select set. And add the source to the collection of Selection.SelectionSources. SelectionA(or B).Selection attribute HasSelectionSources=true. e.g. the code below will use first and second SelectionSets as source.
SelectionSet selectionSetA = (doc.SelectionSets.Value[0] as SelectionSet);
SelectionSet selectionSetB = (doc.SelectionSets.Value[1] as SelectionSet);
clashTest.SelectionA.Selection.SelectionSources.Add(doc.SelectionSets.CreateSelectionSource(selectionSetA));
clashTest.SelectionB.Selection.SelectionSources.Add(doc.SelectionSets.CreateSelectionSource(selectionSetB));


Leave a Reply