Autodesk® Navisworks® 2013 software has exposed some new .NET APIs. The Clash Detection API is exposed. The TimeLiner API has continued to be enhanced since Navisworks 2013 TimeLiner feature includes Cost and thus provides 5D simulations. On the product side, Navisworks can not only open the file of the native Autodesk® Revit® format, but also import Grid and Level from a Revit file and the relevant API methods have been provided as well. In the main product, you will also find the ability to drag the Current Selection from the main window and selection tree which we plan to allow third party applications to use in Viewer controls. We also exposed Current Viewpoint, Saved Viewpoints and Camera. NWCreate now supports the creation of Grids and Levels. In addition, if you need to make use of the COM API, you might be glad to see the COM samples migrated from VB6 to C#.
This article series will introduce the new APIs. In the first section, we take a look at Clash Detection. If you are professional with Navisworks API, you could just go ahead to enjoy the SDK sample in <Navisworks Manage 2013>\api\net\examples\PlugIns\ClashDetective.
The Clash API allows you to access Clash Test, Clash Result and relevant information. First, you need to add the assembly <Navisworks Path>\Autodesk.Navisworks.Clash.dll to your plug-in and import the namespace: Autodesk.Navisworks.Api.Clash.
Following are the main classes of Clash .NET API:
• DocumentClash: provides access to the various document-parts associated with a clash.
• DocumentClashTests: the document-part that holds the currently defined clash tests to access clash tests also provides the methods to modify tests or results.
• ClashTest: a clash-test, including all its settings and results.
• ClashResult: represents a single geometry clash detected in a clash test.
• ClashResultGroup: permits grouping of multiple clash results together which can represent different aspects of the same issues
Get Clash
The Document class has a method called GetClash() which provides access to the DocumentClash object. DocumentClash.TestsData in turn, provides access to an object named DocumentClashTests which allows us to access all the clash tests. The Tests property on this DocumentClashTests helps get each test-related information like display name, tolerance, simulation type, etc. The Children property of each ClashTest helps further drill down to ClashResultGroup and further into each ClashResult. The code sample below shows how to get some information of the tests and drill down to the results and write the information to a text file.
using System.IO;
using System.Windows.Forms;
using Autodesk.Navisworks.Api;
using Autodesk.Navisworks.Api.DocumentParts;
using Autodesk.Navisworks.Api.Clash;
// Sample: dump clash
private void dumpClash()
{
// create a stream to dump clash information
MessageBox.Show("will dump Clash to c:\\dumpClash.txt");
StreamWriter sw = File.CreateText("c:\\dumpClash.txt");
Document document =
Autodesk.Navisworks.Api.Application.ActiveDocument;
DocumentClash documentClash = document.GetClash();
DocumentClashTests oDCT = documentClash.TestsData;
//dump clash tests
foreach (ClashTest test in oDCT.Tests)
{
sw.WriteLine("***Test: " +
test.DisplayName + "***");
sw.WriteLine(" Status: " +
test.Status.ToString());
sw.WriteLine(" TestType: " +
test.TestType.ToString());
if (test.LastRun != null)
sw.WriteLine(" LastRun: " +
test.LastRun.Value.ToShortDateString());
sw.WriteLine(" tolerance: " +
test.Tolerance);
sw.WriteLine(" comments: " +
test.Comments);
sw.WriteLine(" SimulationType: " +
test.SimulationType.ToString());
sw.WriteLine(" SimulationStep: " +
test.SimulationStep.ToString());
sw.WriteLine(" ---Results---");
// dump Clash Result
foreach (SavedItem issue in test.Children)
{
ClashResultGroup group =
issue as ClashResultGroup;
if (null != group)
{
sw.WriteLine(" test result group: " +
group.DisplayName);
sw.WriteLine(" group status: " +
group.Status.ToString());
foreach (SavedItem issue1 in group.Children)
{
ClashResult rt1 = issue as ClashResult;
if (null != rt1)
writeClashResult(rt1, sw);
}
}
ClashResult rt = issue as ClashResult;
if (null != rt)
writeClashResult(rt, sw);
}//Result
} //Test
MessageBox.Show("done!");
sw.Close();
}
private void writeClashResult(ClashResult rt,
StreamWriter sw)
{
//dump some information of the result
sw.WriteLine(" test result: " +
rt.DisplayName);
if (rt.CreatedTime != null)
sw.WriteLine(" CreatedTime: " +
rt.CreatedTime.ToString());
sw.WriteLine(" Status: " +
rt.Status.ToString());
sw.WriteLine(" ApprovedBy: " +
rt.ApprovedBy);
if (rt.Center != null)
sw.WriteLine(" Center[{0},{1},{2}]: ",
rt.Center.X, rt.Center.Y, rt.Center.Z);
sw.WriteLine(" SimulationType: " +
rt.SimulationType.ToString());
}
ClashTest configures the selections which are involved in a test. ClashTestResult returns the selections which are collisions. The code snippet below gets the selections from one test and one result, and highlights the selection2 of one result.
//Sample: Get selection information of Clash Test and Clash Result
private void getSelection()
{
Document document = Application.ActiveDocument;
DocumentClash documentClash = document.GetClash();
DocumentClashTests oDCT = documentClash.TestsData;
ClashTest t = documentClash.TestsData.Tests[0] as ClashTest;
if (t != null)
{
//get SelectionA and SelectionB of one Clash Test
ModelItemCollection oSelA = t.SelectionA.Selection.GetSelectedItems();
ModelItemCollection oSelB = t.SelectionB.Selection.GetSelectedItems();
ClashResult rt = t.Children[0] as ClashResult;
if (rt != null)
{
//get Clash Selections of the result
ModelItemCollection oSel1 = rt.Selection1;
ModelItemCollection oSel2 = rt.Selection2;
//highlight Selection2 of the result
document.CurrentSelection.CopyFrom(oSel2);
}
}
}
There are two methods to run all tests or specific test.
DocumentClashTests oDCT = documentClash.TestsData;
//run all tests
// oDCT.TestsRunAllTests();
//or run one test
ClashTest oFirstTest = oDCT.Tests[0] as ClashTest;
oDCT.TestsRunTest(oFirstTest);
Next, we will look at how to update clash.
(to be continued)