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)

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)

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)

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)

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

Well, that’s the end of the tutorial, you can download the complete project source code from here. Cheers!
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.
regards
LikeLike
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!
LikeLike