Create Macros

Use these steps to create macros using the Macro Manager.

In Revit, all Application-level macros use the Application keyword for addressing the application object in both C#, VB.NET, Ruby and Python. This includes all the application-wide data and settings.

In Revit-specific Document-level macros, the Document keyword, in C#, VB.NET, Ruby and Python returns the API Document object. If you need to access the Application object from a Document-level macro, use:

Document.Application

Note: If the application or current document already contains macros, macros must be enabled in the Macro Security settings.

Macros creation overview

  1. In the Macro Manager, select the Application tab (for application-level macros) or a Project tab (for document-level macros) where the macro will be placed.
  2. In the Create section of the Macro Manager dialog, click Macro.

    The Create a New Macro dialog opens.

  3. Enter the following information:
    • Enter a name in the Macro name field.
    • Select a parent module from the Macro in list. The language of the parent module will define the language of the macro.
    • Optionally, add a brief description of the macro in the Description field.
  4. Click OK.

    The new macro is placed in the parent module in the Macro Manager.

    The Revit macro IDE application launches to write the macros. It displays a starting template for the macros in a specific programming language.

    For example, in a C# template for an application-level macros, the Revit macro IDE has already:

    • Included the necessary using directives.
    • Identified the module namespace (MacroAppCS in the graphic above).
    • Started the ThisApplication class definition.
    • Started the methods for Module_Startup() and Module_Shutdown().
    • Started your new macro's method (MyFirstMacrosApp in the graphic above), giving you the opportunity to add your implementation code between the braces.

    Also, note that the Revit macro IDE Project Explorer shows your context.

  5. In the main window of the IDE, you can now enter your source code.
  6. Click FileSave <macro name>, then close the Revit macro IDE.
  7. Repeat steps 1 through 6 for any additional macros needed in the module.
    Note: Remember that you must successfully build and save module projects in the Revit macro IDE, before they will display in the Macro Manager's categorized list.

    Optional Tools

    • Click Description to view a description of a selected module or macro in its entirety. This is useful when the Description column of the Macro Manager is truncated.