Creating Navisworks Add-Ins

This post will be covered how to create an Autodesk® Navisworks® Add-Ins that we will be creating a file-path info dialog for the current file and the appended files. I will be using Visual Studio 2017v and Navisworks® 2020v.

FileInfoApp – Demo

Let’s start our project by launching Visual Studio and create a new project > choose Class Library (.Net Framework) and name it “FileInfoApp” (figure 1.1).

figure 1.1

After this, you should be seeing namespace class window as shown in figure 1.2 below.

figure 1.2

In the Solution Explorer panel, right-click on References > Add Reference > add Navisworks API library and WindowsForms library as our project references. (figure 1.3, 1.4)

figure 1.3

Click “Browse …” button on Reference Manager Window and add these libraries Autodesk.Navisworks.Api.dll from Navisworks product installation directory, the default path is C:\Program Files\Autodesk\Navisworks Manage 20xx (figure 1.3) and System.Window.Forms from Assemblies. (figure 1. 4)

figure 1.4

Select two libraries and right-click go to properties to change local copy value. (figure i1, i2)

Import library assemblies from Navisworks API and WindowsFroms references as shown in figure 1.5. *Note: to avoid ambiguous reference between Navisworks API and WindowsFroms, assign WindowsFroms assemblies as wf. (using wf = System.Windows.Froms;)

figure 1.5

Rename the class name as MainClass, add an attribute PluginAttribute with Name, DeveloperId and optional parameters; DisplayName and ToopTip (figure 1.6). If you want to add more see the full list of properties here.

figure 1.6

Just a short discussion for PluginAttribue attribute, if you have some experience/knowledge about creating Autodesk® Revit® add-ins, it is something like an add-ins manifest xaml file that contains meta data about the add-in.

Add AddInPlugin interface, this class can be used as a base class for adding an executable plugin with the implementation of its abstract method, Execute. Execute method has a list of string[] parameter and return an integer value, it could be 0. 1… (figure 1.7) . By default add-in will be shown in Tool add-ins 1 tab. See the list of other available locations from here.

figure 1.7

In the Execute method, first get the Document object from the application with Application.ActiveDocument property. Create a variable name, message, to assign and display our current file and the appended files paths by using a WindowForms.MessageBox. To get the appended files paths, use Models property from the document object and from each of the model uses FileName property to get the particular file path. Finally, display the message string from the MessageBox.Show method. (figure 1.8)

public class MainClass : AddInPlugin
    {
        public override int Execute(params string[] parameters)
        {
            // get document from application
            Document document = Application.ActiveDocument;
            // info message - current file path with appended files
            string message = "Current File : " + document.CurrentFileName + 
                              "\nAppend File : " ;
            // get appended models from current document
            DocumentModels models = document.Models;
            // each model
            foreach(Model model in models)
            {
                // get filepath with index
                message += "\n         "+ (models.IndexOf(model)+1).ToString() +". "+ model.FileName;
            }
            // display message
            wf.MessageBox.Show(message);
            // int return
            return 0;
        }
    }
figure 1.8

The last part is to add Post-build Event Command Line from Build Events, xcopy/Y "$(TargetDir)." "D:\Autodesk\Navisworks Manage 2020\Plugins\$(TargetName)\" , to copy this project DLL to Navisworks installation directory’s Plugins folder. (figure 1.9)

figure 1.9

To start external program for debugging, Browse... > Navisworks installation directory > Roamer.exe . (figure 1.10). Finally, build the project or press F5.

figure 1.10

Well, this is the end of our Navisworks FileInfoApp tutorial. You can get the complete source from here. Cheers!

How To Navisworks Navisworks Add-Ins

min.naung View All →

Site Founder and Developer.

4 Comments Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: