|
![]() |
The Automation part of the .NET API is a small assembly that can be referenced by developer applications. It contains enough to start Navisworks and perform some basic actions; however complex actions should be achieved using a plug-in which can still be called through Automation. Here we will create a simple Application to demonstrate the rudiments of creating an application using the Automation features to merge two AutoCAD DWG files into a single Navisworks NWD file.
![]() |
---|
the same set of actions that can be invoked in Automation can also be invoked from the Navisworks command line. |
This example can be found in: '<drive>:\Program Files\Autodesk\Navisworks <Product> 2015\api\net\examples\Automation\FileManipulation'
Overview
Step | Key Information |
---|---|
Create Blank Project | |
Add API Reference | Autodesk.Navisworks.Automation.dll |
Add any other references | |
Add implementation | |
Build | |
Run Program | This program takes input from two AutoCAD .DWG files which can be copied from the FileManipulation sample into the project output directory. |
To create an application using Automation
-
Create the calling application.
-
Add the required API references.
-
Add the code which merges two files (hello.dwg and world.dwg) into a single Navisworks file (hello_world.nwd):
CopyMerging Files into a Navisworks Document
Autodesk.Navisworks.Api.Automation.NavisworksApplication automationApplication = null; try { //Get Current Working directory string workingDir = System.IO.Directory.GetCurrentDirectory().TrimEnd('\\'); //create NavisworksApplication automation object automationApplication = new Autodesk.Navisworks.Api.Automation.NavisworksApplication(); //disable progress whilst we do this procedure automationApplication.DisableProgress(); //Open two AutoCAD files automationApplication.OpenFile(workingDir + "\\hello.dwg", workingDir + "\\world.dwg"); //Save the combination into a Navisworks file automationApplication.SaveFile(workingDir + "\\hello_world.nwd"); //Re-enable progress automationApplication.EnableProgress(); } catch (Autodesk.Navisworks.Api.Automation.AutomationException e) { //An error occurred, display it to the user System.Windows.Forms.MessageBox.Show("Error: " + e.Message); } catch (Autodesk.Navisworks.Api.Automation.AutomationDocumentFileException e) { //An error occurred, display it to the user System.Windows.Forms.MessageBox.Show("Error: " + e.Message); } finally { if (automationApplication != null) { automationApplication.Dispose(); automationApplication = null; } }
Calling plug-ins through Automation
It is also possible to invoke a plug-in using Automation and to receive a reply in the form of a status code. For example:

string aString = "Hello"; Autodesk.Navisworks.Api.Automation.NavisworksApplication navisworksApplication = new Autodesk.Navisworks.Api.Automation.NavisworksApplication(); // Execute command on our message receiver int retval = navisworksApplication.ExecuteAddInPlugin("BasicPlugIn.ABasicPlugin.ADSK", aString); //Show the result received from the plugin MessageBox.Show(String.Format("Plugin returned {0}", retval));