Create Clash Selection with Selection Set

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:

User interface of Navisworks Clash Detective showing selections for Clash Test 'MyTest'. Selection A displays a compact model tree while Selection B shows the standard model tree with various model items listed.

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);
Screenshot of the Navisworks Clash Detective interface showing 'Selection A' with items from the compact model tree and 'Selection B' with items from the standard model tree for a clash test.

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));
Screenshot of the Navisworks Clash Detective interface, displaying the selection sets for two clash tests named MyTest, with options for Selection A and B showing items 'STEEL' and 'PIPING_2'.


Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading