Revit API : Dockable Window (A New Edition)

This is a new edition of DockableWindow post, the previous post is here. In the previous post, we have to register our DockableWindow during zero document stage and, after the document loaded, display the window by executing a command button. In this edition, we will register our DockableWindow while Revit® Application is starting/launching and display the window by executing a command button. We will create a Dockable WPF Control hosting a Web Browser and showing twentytwo.space website.

Dockable Window Demo (20s)

The IExternalApplication interface has two abstract methods, OnStartup() and OnShutdown(), Revit calls OnStartup event method when it starts/launches, we will register our DockableWindow in this event method, and calls OnShutdown event method when it closes.

figure 1.0 – OnStartup Event Method

This time we only have to create Show UI button and attach it to Show Command. In the OnStartup event method, to do the following steps;

  • Create a Ribbon Panel name “TwentyTwo Sample” under Revit Add-Ins Tab.
  • Get current assembly path which is the location of this current project’s DLL file.
  • Create a button for Show Command and add to the created “TwentyTwo Sample” panel.
  • Assign ToolTip and Images properties respectively.
  • Register Dockable Window (figure 1.0)

GetResourceImage method, to collect our image files that we just embedded in this current assembly resource file for Show command button. Method includes two parameters : (Assembly) an assembly , (string) name of an image and returns an ImageSource object. (figure 1.1)

figure 1.1 – GetResourceImage Method

In RegisterDockablePane method, assign an instance of the DockablePaneViewer() to a field and create a new DockablePaneId with a GUID, Globally Unique Identifier, you can generate and get a number from here. RegisterDockablePane method needs three parameters: an Id, a caption and a dockable window. (figure 1.2)

figure 1.2 – RegisterDockablePane Method

In Show command class, get the registered Dockable Window with the same GUID value was given in the registration method and display it with Show() method (figure 1.3).

figure 1.3 – Show Command

Add new item > Select User Control (WPF) and name it “DockablePaneViewer.xaml”. (figure 1.4)

figure 1.4 – DockablePaneViewer UserControl

Change the Window to Page tag as recommended in Revit API Developer Guide . And just have to add a WebBrowser tag with Name and Source (a webpage to navigate and display). (figure 1.5)

figure 1.5 – DockablePaneViewer.xaml

In DockablePaneViewer.xaml.cs , we’ll subscribe WebBrowser’s Loaded Event with a callback method to hide unwanted JavaScript pop-up dialogs while web page loading. Implementation of the IDockablePaneProvider interface and its abstract method named SetupDockablePane. SetupDockablePane() method has one parameter of type DockablePaneProviderData, which is a container for information about our dockable window. And we’ll set FrameworkElement and Initial State of its properties. (figure 1.6)

figure 1.6 – DockablePaneViewer.xaml.cs

This callback, HideJsScriptErrors, method silent unwanted pop-up script errors (figure 1.7)

figure 1.7 – HideScriptErrors

In Build Events tab, edit Pre-build event : xcopy /Y "$(ProjectDir)WPFDockablePaneAddIns2.addin" "$(AppData)\Autodesk\Revit\Addins\2023" – to copy the AddIn manifest file, “RevitAddInsWPFSample.addin”, to Revit’s system location. (figure 1.8, 1.9)

figure 1.8 – WPFDockablePaneAddIns2.addin
figure 1.9 – Pre-Build Event Command Line

That’s all for this tutorial, you can get the complete source code from here, Cheers!

Advertisement

3 thoughts on “Revit API : Dockable Window (A New Edition)

  1. It looks interesting, but have you tried using it to open two documents in Revit at once, like opening or editing a family or opening two Revit projects in one session? I believe Revit will crash.

    Like

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 )

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.