Support DLL, Zero Doc State and Forge Accelerators

If you are interested in diving deep into Forge programming, don't miss the upcoming deadline for proposals for the Boston Forge accelerator!

Looking at the Revit API, I implemented a sample demonstrating how to enable ribbon items in zero document state back in 2011, for Revit 2011.

How long would it take to port such an add-in to Revit 2019?

Well, this one took ten or twenty minutes, including some debugging, screen snapshots, and documentation.

Admittedly, it is an absolutely trivial example :-)

Let's look at that, and another recurring topic, on loading add-in support DLLs:

External command in zero document state

Migrating the ZeroDocPanel to Revit 2019

John raised an issue in the Revit API discussion forum thread on IsCommandAvailable causing a nullref exception.

That prompted me to update my original implementation to enable ribbon items in zero document state in Revit 2011 and test it in Revit 2019.

I performed the flat migration from Revit 2011 to Revit 2019, i.e., updated the Revit API assembly references and set the .NET framework to version 4.7.

Next, I tried to load and debug the add-in.

Revit displayed an error due to a lack of the VendorId tag in the add-in manifest:

External Tools – No VendorId Node for Add-in

Failed to initialize the add-in “ZeroDocPanel.addin” because the add-in registration is missing the required value of VendorId node. The VendorId node identify the vendor of the add-in application. For Revit to run the add-in, you must register the node defined in manifest “ZeroDocPanel.addin” file.

VendorId node missing in add-in manifest

The VendorId node had not yet been invented in 2011   :-)

I added the vendor id, and all was well.

I debugged the add-in and ensured that the OnStartup and IsCommandAvailable methods are both called just as expected.

The external command is listed and can be executed in the external tools menu in zero document state, cf. the screen snapshot above.

The command execution displays its little task dialogue:

Zero document state external command displaying a task dialogue

The complete add-in sample including Visual Studio project, source code and add-in manifest now lives in its own ZeroDocPanel GitHub repository.

Here are all the commits I made for the migration:

Loading Add-In Support DLLs

In another Revit API discussion forum thread on loading the missing System.ComponentModel.Annotations v4.2.0.0, my colleague Jim Jia suggested using an assembly resolver reacting to the AppDomain.CurrentDomain.AssemblyResolve event:

You may try to force loading the assembly if it cannot be loaded successfully. The code snippet below should provide a safe solution, per my experience; hope it is helpful:

  Result Execute(
    ExternalCommandData commandData,
    ref string message,
    ElementSet elements )
    // Try to load assembly if Revit command fails to load it.

      += new ResolveEventHandler(
        OnAssemblyResolve );

    // your other code...

  Assembly OnAssemblyResolve( object sender, ResolveEventArgs args )
    Assembly a = null;

    if( args.Name.Contains( "ComponentModel.Annotations" ) )
      string assemblyFile = Path.Combine( addinDir, 
        "ComponentModel.Annotations.dll" );

      ifFile.Exists( assemblyFile ) )
        a = Assembly.LoadFrom( assemblyFile );
    return a;

We explored some related issues and had success with this approach in the past, e.g., here:

Rome and Boston Forge Accelerators

I recently mentioned that I am attending the Forge accelerator in Rome end of this month, September 24-28.

I expect that it is too late to decide to join that one now.

However, you can still submit proposals for the Boston accelerator taking place in October – note that the deadline for submitting one is next Saturday, September 15:

The Forge team is finishing the review of proposals for the upcoming accelerator taking place in the Autodesk Boston office October 1-5.

Note that the BIM 360 Issue API is now publicly available, cf. the .NET and Node.js samples introducing BIM 360 Issues API and accessing BIM 360 Issues API with Node.js.

You can now also simulate the use of the Design Automation API for Revit on your machine (note that it is still in private beta!).

Therefore, the Forge team would love to support you and your software development team in working intensively on a Forge-based project making use of these new technologies with one-on-one support and advice from Autodesk Forge API experts.

If you have an idea for a new web or mobile application based on Autodesk Forge APIs, or need help getting an existing application working, then come along to the event.

There is no cost to attend the accelerator, other than your own travel and living expenses.

However, we do ask that you submit a proposal as part of your application so that we can verify that the intended use of the Autodesk Forge APIs in your project is feasible.

You can apply and submit your proposal here.

For more information, please visit the Forge Accelerator website.