Migrating SDK Samples to the Revit Macro IDE

The Revit SDK contains two samples folders:

\Revit SDK <release>\Software Development Kit\Samples\...

\Revit SDK <release>\Software Development Kit\Macro Samples\...

The programs in the SDK's \Samples\ folder use the standard Revit API. We refer to these samples as the SDK sample code, as distinct from the Revit macro samples.

If you want to use the SDK sample code for macros, modifications are needed. Follow the steps in this section. For a programming language, we will show C# examples. However these instructions also apply to the VB.NET versions of the SDK samples.

Initial Steps

The initial steps to migrate standard API samples from the SDK into your Revit macro IDE project are similar to the section Integrating Macros into the Revit IDE. Except, instead of copying files from the SDK's \Macro Samples\<sample-name>\... folders, you will copy files from the SDK's \Samples\<sample-name>\... folders.

To review, the steps are:

  1. In the IDE, add required references.
  2. In the IDE, create folders for the SDK samples you want to migrate.
  3. In Windows Explorer, copy the SDK standard API samples’ files to the corresponding file system folders.
  4. In the IDE, add existing files to the macro project.

Update the SDK Samples’ Code

In the Revit macro IDE, the IExternalCommand interface is not available or used. In the SDK standard API sample code, you must update the class that inherits from this interface:

Code Example Before Edits

The following code snippet is from a program that uses the standard Revit API:

Code Example After Edits

In the Revit macro IDE, we need to update the code as follows. This example shows an application-level macro. The method RunSampleRooms() is the entry for this macro sample. Notice that we used the this pointer to replace commandData.Application.

Additional Migration Notes for SDK Standard API Samples