Saturday, May 3, 2008

Revit Structure API & VSTA Overview

Revit Structure provides an Application Programming Interface (API) that allows you to extend the functionality of the product. Starting with Revit Structure 2009, you can use the API to define macros that can be saved with the application or project. For example, you might define a macro to add a grid to your project, to rotate a selected object, or to collect information about the square footage of all the rooms in your structure. Other general examples include:
  • Locating and extracting Revit content to external files
  • Changing geometry or parameters
  • Creating elements
  • Importing/exporting external file formats

Macro support is provided by the Revit VSTA plug-in, which you can install in conjunction with your existing Revit installation.

First, let's answer the question: “what are macros, and why would you use them”? Macros are programs that are designed to help you save time, by automating repetitive tasks. Each macro performs a series of pre-defined steps to accomplish a particular task. The steps should be repeatable and the actions predictable.


Revit provides an Application Programming Interface (API) that allows you to extend the functionality of the product. Experienced developers and Autodesk partners may already know that the Revit API lets them add customized commands to the Tools > External Commands menu, or add new menus and toolbars.


In addition to those API extensions, starting in the Revit 2009 release you can use the API to define macros that run in Revit. Unlike external commands and external applications, the macro functionality is available to Revit after you install an “add-in” called Revit VSTA. We will explain the API differences later in this topic, but for experienced developers, note that you do not need to register the macros in Revit.ini, or add RevitAPI.dll as a reference.


VSTA is an acronym for Visual Studio Tools for Applications. It is a Microsoft technology that provides the .NET framework for creating macros in C# and VB.NET based on specific applications. VSTA is the next evolution of Visual Basic for Applications (VBA) that appears in several existing Autodesk applications.


Expect API Changes

It is very likely that the Revit API will change in subsequent product releases. This means that after installing the next Revit release, you will need to edit and rebuild your macros to reflect the API changes.


Revit VSTA Components

To create macros, you must install Revit VSTA on top of your existing Revit installation. The Revit product and Revit VSTA versions must be the same.

You can use the Revit VSTA macro features in all Revit products: Revit Architecture, Revit Structure, and Revit MEP. However, a separate Revit VSTA install, described in this topic, is required for each Revit product in which you want to run macros. In this topic, we refer to any of these products generically as “Revit” without a further qualifier.

Once installed, Revit VSTA provides:

  • New items on the toolbar’s Tools menu:
    • Tools > Macros > Macros
    • Tools > Macros > Launch VSTA IDE
  • Macro Manager, a user interface launched by the Tools > Macros > Macros menu option. Macro Manager presents a list of macros you built previously that you can run, edit, or debug (StepInto). Macro Manager also provides options to create new macros using different types of templates.
  • An Integrated Development Environment (IDE) built into the product, the Revit VSTA IDE. You can launch it several ways:
    • Tools > Macros > Launch VSTA IDE
    • From the Macro Manager, by selecting the New, Edit, or StepInto buttons
  • Full access to the Revit API.

Workflow Overview: Initial Steps with Macros

The following diagram illustrates the initial steps with Revit VSTA and macro development:


{Revit Structure 2009 User's Guide}

No comments:

 
Clicky Web Analytics