Navisworks API : Event and EventWatcherPlugin

Welcome to the fifth tutorial of Navisworks® API series, this post is to cover how to subscribe/unsubscribe the Application & Document Events and another type of plugin called EventWatcherPlugin that can’t be seen from the Navisworks® user-interface. In this tutorial, we’ll create an event watcher add-ins that override the transparency of all the unselected model items in the document.


And this task is Lab-9 exercise from Navisworks® SDK.(figure 1.0)

So, first things first, setting up Navisworks® Add-Ins project in the visual studio, you can follow Creating Navisworks Add-Ins tutorial to set up the project. When you are ready, in Plugin attribute omit two properties DisplayName, Tooltip since our add-ins no longer display in the UI (there is no issue even if you provided). In the MainClass implement EventWatcherPlugin interface which includes OnLoaded – method called when application start after Add-Ins is loaded/created and OnUnloading – method called when application closing before Add-Ins is unloaded. These are the recommended places to subscribe & unsubscribe API Events accordingly. (figure 1.1)

figure 1.1 – EventWatcherPlugin Interface and OnLoaded & OnUnloading methods

In OnLoaded method, subscribe an Application event named ActiveDocumentChanged – occurs when the ActiveDocument has changed. Every event must provide an event handler method, we will write a method, Application_ActiveDocumentChanged and provide as an event handler method. And to unsubscribe the ActiveDocumentChanged event in OnUnloading method respectively.(figure 1.2)

figure 1.2 – OnLoaded method

In Application_ActiveDocumentChanged event handler method, check the active document status and to subscribe CurrentSelection.Changed a document event. So, why can’t we just subscribe this event, in the first place, in OnLoaded method ? No, it will raise an error. The reason is – while the application loading, the active document object is does not existed yet. (figure 1.3)

figure 1.3 – Application_ActiveDocumentChanged

In CurrentSelection_Changed event handler method, get the current selected items and check whether null or has any selected items. Create an empty modelitemcollection, copy & invert the selected items and override the transparency. Finally, reset all the modelitems transparency when there is no modelitem is selected. (figure 1.4)

figure 1.4 – CurrentSelection_Changed

Below demo is just to explicitly show how methods are being called when events are triggered.

Method Called Demo

Well, that’s the end of the tutorial, you can download the complete project source code from here. Cheers!


2 thoughts on “Navisworks API : Event and EventWatcherPlugin

  1. Hello Min, Very helpful post. Do you by any chance know how I can export Navisworks Clash Viewpoint and show it in Revit? Any tip will be appreciated.



  2. Hi Dodzi,
    First of all, thanks for your donation and I really appreciate it. For your question, maybe some tips:
    1. Export your clash report in HTML or XML … it will automatically export Clash Viewport as JPG files.
    2. Create Drafting Views and Import these JPG files in your Revit.

    I think you got the idea, and thanks again for your donation. Cheers!


Leave a Reply

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

You are commenting using your 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.