Revit WPF Add-Ins and Template

The long-standing topic of WinForms versus WPF for Revit add-in user interface seems to be nearing a conclusion:

WinForms or WPF?

An extensive discussion in the Revit API discussion forum on the question of using WinForms or WPF in Revit add-ins is pretty clearly recommending WPF as the better choice, for various reasons:

The only downside seems to be that many existing samples in the Revit SDK and elsewhere use WinForms.

That said, the Revit IFC open source UI does use WPF, so you could grab all the samples you need from there, if you like.

Here is a pretty fine 56-minute guide for getting started, the C# WPF UI Tutorial:

Revit WPF Template

The latest contribution to this thread comes from Micah kraftwerk15 Gray:

We were having a conversation on Twitter and had Petr Mitev share a template example of WPF in the Revit WPF Template GitHub repository.

I'm sure there are others out there, but this adds in the Revit context that those building for the Revit API will have to get used to. Many existing examples will not show how the WPF interacts with the Revit API.

Ever so many thanks to Micah and Petr for putting together, sharing and documenting this valuable resource!

Revit WPF Template Readme

The template is well documented and includes built-in support for automatic documentation of the add-ins you create using it.

Here are some excerpts from the GitHub readme file:

WPF Template for Revit Add-Ins including wrapped external methods for execution in a "Valid Revit API Context".

Window A
Window B
Window C
Revit ribbon

Build

  1. Clone/download the repository and open the .sln at the root of the repository with Microsoft Visual Studio.
  2. Re-link references to RevitAPI.dll and others which may be missing.
  3. Build the solution – Building the solution will automatically create and copy the add-in files to the folder for Revit 2019.
  4. Open Revit – Upon opening Revit 2019, there should be a tab called "Template" in Revit, with a button to launch the WPF add-in.

Customize

In order to use this as a starter for your application, make sure you first refactor the content in the application files (namespace, assembly name, classes, GUID, etc.) and remove the assets folder in the repository.

A guide to refactoring can be found in the docs folder.

Documentation

Documentation is created using Sandcastle Help File Builder by compiling the docstrings from the compiled .dll and .xml files generated by Visual Studio upon build. The Sandcastle project can be launched through the RevitTemplate.shfbproj file in the docs folder.

The documentation can be found in the docs folder in the root of the repository. The following documentation sources are created:

  1. .chm – This is an interactive help file which can be launched by double-clicking on any Windows machine.
  2. index.html – This is the documentation compiled for web deployment.