|
![]() |
Through the Clash Api developers have access to the majority of Clash Detective functionality and data available through the GUI. Clash data is stored as a hierarchy of data derived from SavedItem similar to Selection Sets.
Details
Assembly | Autodesk.Navisworks.Clash.dll |
Namespace | Autodesk.Navisworks.Api.Clash |
Access
Access to Clash Detective functionality is via the Document..::..Clash property. If Clash Detective is available in your product, then this is non-null. The returned interface must be cast to a DocumentClash before it can be used.
If you are using C# and using the Autodesk.Navisworks.Api.Clash namespace then the extension method: DocumentExtensions..::..GetClash can be used for conveninence to handle the cast for you.

DocumentClash document_clash =
Autodesk.Navisworks.Api.Application.MainDocument.Clash
as DocumentClash;
DocumentClash document_clash2 =
Autodesk.Navisworks.Api.Application.MainDocument.GetClash();
Classes
All classes are contained in the Autodesk.Navisworks.Api.Clash Namespace.
Class | Key Information |
---|---|
DocumentClash |
An outer class providing access to all document-parts associated with clash detective. |
DocumentClashTests |
The document part holding the ClashTests collection (Tests) and the edit-methods required to manipulate them (TestsAddCopy, TestsRunTest etc.) |
ClashTest |
A single clash-test which can be configured and run. After running, the results of the test are found in its (Children) collection. |
ClashSelection |
A class grouping the Selection, SelfIntersect flag, and PrimitiveTypes flags enumeration.
ClashTest contains two of these for SelectionA and SelectionB. |
IClashResult |
A common interface supported by ClashResultGroup and ClashResult to allow unified access to their properties. |
ClashResultGroup |
A group of ClashResults. Groups cannot be nested, but groups or results can both be added to a ClashTests children. A group's nested results are found in its Children collection. A group without any children has only very limited functionality (most properties reflect child-properties and thus become unsettable without a child.) |
ClashResult |
A single interference found in the model. |
Examples
As mentioned above, most Clash operations can be achieved through the API. The following examples demonstrate the common operations.

void ClashIterateResults() { DocumentClash document_clash = Autodesk.Navisworks.Api.Application.MainDocument.GetClash(); foreach (ClashTest test in document_clash.TestsData.Tests) { RecurseChildren(test); } } // GroupItem is a base-class of ClashTest. If we needed to access // the test's properties, we could declare "group" as that ClashTest // but then would not be able to use this method to recurse further into // unrelated type ClashResultGroup and would need to write a // separate method. public static void RecurseChildren(GroupItem group) { foreach (SavedItem child in group.Children) { /* If we only wanted to access first-level children * without reference to whether they were groups or results * then we could: * * // access groups and results via shared interface * IClashResult result = child as IClashResult; * * operate on that and not recurse further. */ // GroupItem is the base-class of ClashResultGroup which defines // group-like behaviour, if we needed to access ay ClashResultGroup properties // we could cast to that equivalently... GroupItem child_group = child as GroupItem; // is this a group? if (child_group != null) { // operate on the group's children RecurseChildren(child_group); } else { // Not a group, so must be a result. ClashResult result = child as ClashResult; // act on result... } } }

DocumentClash document_clash = Autodesk.Navisworks.Api.Application.MainDocument.GetClash(); // get an existing test ClashTest test = document_clash.TestsData.Tests[0] as ClashTest; // test read from document-part is read-only, create a copy ClashTest new_test = test.CreateCopyWithoutChildren() as ClashTest; // set up some selection settings for our test ClashSelection sel_a = new ClashSelection(); ClashSelection sel_b = new ClashSelection(); // simplest case, put everything into SelectionA, test that against itself // and clear SelectionB sel_a.SelfIntersect = true; sel_a.Selection.SelectAll(); sel_a.PrimitiveTypes = PrimitiveTypes.Triangles; sel_b.SelfIntersect = false; sel_b.Selection.Clear(); new_test.SelectionA.CopyFrom(sel_a); new_test.SelectionB.CopyFrom(sel_b); // let's also change the test-type new_test.TestType = ClashTestType.Clearance; // we'll need a tolerance for that, this is in the model-units of the loaded model // (NOT the display-units) new_test.Tolerance = 0.1; // Now edit the test stored in the document using properties from our changed // copy. Note that _Edit_ sets properties on only the test and does not touch // any child-results. Edit is thus far more efficient for changing only one point // in the hierarchy when there are many children. document_clash.TestsData.TestsEditTestFromCopy(test, new_test);

DocumentClash document_clash = Autodesk.Navisworks.Api.Application.MainDocument.GetClash(); // get an existing test ClashTest test = document_clash.TestsData.Tests[test_index] as ClashTest; // test read from document-part is read-only, create a copy ClashTest new_test = test.CreateCopy() as ClashTest; // edit the properties, results and result-groups of the new_test // Now replace the test stored in the document with the whole of // our edited hierarchy. This is efficient as a way of doing many // edits in one operation. document_clash.TestsData.TestsReplaceWithCopy(test_index, new_test);

DocumentClash document_clash = Autodesk.Navisworks.Api.Application.MainDocument.GetClash(); // get an existing test ClashTest test = document_clash.TestsData.Tests[test_index] as ClashTest; IClashResult result = test.Children[result_index] as IClashResult; // Now edit the status of the result stored in the document. // // Note that this method works the same on results or result-groups. // In the latter case if the property is one derived from child-results, // (see individual properties) it sets it on all child-results. It is an error (for a result-group) to try and // set a property derived from child-results when there are no children. // // _Edit_ sets properties on only the result and does not touch // any child-results. Edit is thus far more efficient for changing only one point // in the hierarchy when there are many children. // // The paradigm used here is different from the "ReplaceEntireObject" approach of // (for example) TestsEditTestFromCopy because of the complexity of treating // groups and individual results correctly, and detecting all possible errors. document_clash.TestsData.TestsEditResultStatus(result, ClashResultStatus.Approved);

DocumentClash document_clash = Autodesk.Navisworks.Api.Application.MainDocument.GetClash(); // get an existing test ClashTest test = document_clash.TestsData.Tests[test_index] as ClashTest; // run the test, repeats the run whether the test believes it is "Complete" or not // new results may be added, existing "New" results marked "Active" and non-reproducible results removed. document_clash.TestsData.TestsRunTest(test);