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. See
Macro Security.
Macros creation overview
- 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.
- In the Create section of the Macro Manager dialog, click Macro.
The Create a New Macro dialog opens.
- 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.
- 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.
- In the main window of the IDE, you can now enter your source code. See Macro Source Code Examples.
- Click FileSave <macro name>, then close the Revit macro IDE.
- 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. See
Building Macros in the Revit Macro IDE.
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.
- See Modifying and Removing Modules and Macros.