How to Use These Macros – Basic Overview

UPDATE: I’ve posted a new video showing a simpler example of how to create a macro at

If you are trying to get started with macros, here are some basics.

  1. In the Revit UI, go to the Manage tab
  2. In the Macros panel, click the Macro Manager button
  3. Macros can either be stored in the project (with the source code saved in the RVT file) or on your hard drive so that they are accessible for any RVT on your computer (these are called application macros). On this blog I am creating application macros. To do this, select the “Application” tab.
  4. Create Module
  5. Enter a name. Select C# or VB.NET (the code on my blog is C#). Push OK.
  6. Create Macro.
  7. Enter a name. Push OK.
  8. Go to the SharpDevelop application.
  9. Enter “using” statements at the top of the file – at least the two shown below in bold, possibly others depending on your code.
  10. Enter the text inside the { and } that define the body of the macro.
  11. Click F8. There should be no errors. If there are 2 warnings about processor architecture you can ignore them.
  12. Go back to the Revit Macros dialog. Select your new macro. Push Run.

Your code in SharpDevelop should look like this, depending on the specific macro you are implementing. In bold is the code I added (using statements & GetSheetParams macro).

 * Revit Macro created by SharpDevelop
 * User: HP002
 * Date: 1/2/2013
 * Time: 4:54 PM
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
using System;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;

namespace MyModule
    public partial class ThisApplication
        private void Module_Startup(object sender, EventArgs e)


        private void Module_Shutdown(object sender, EventArgs e)


        #region Revit Macros generated code
        private void InternalStartup()
            this.Startup += new System.EventHandler(Module_Startup);
            this.Shutdown += new System.EventHandler(Module_Shutdown);

        public void GetSheetParams()
            Document doc = this.ActiveUIDocument.Document;
            string sheetInfo = "";
            foreach (Element e in new FilteredElementCollector(doc).OfClass(typeof(ViewSheet)))
                Parameter parameter = e.get_Parameter("CADFile");
                string cadFileData = parameter.AsString();
                sheetInfo += cadFileData + "\n";
            TaskDialog.Show("CADFile", sheetInfo);

14 thoughts on “How to Use These Macros – Basic Overview

  1. When you create a module it already starts up SharpDevelop with some code. When you create a marco it starts up the module code and inserts: [revit macros generated code] public void MyModule(){… It doesn’t fit your description

    • You are right that Revit automatically creates some default code when a new module is created. This is shown in the sample module text of this post and in the video. This code should not be modified, which is why I did not mention it in my post.

  2. Hi Harry,
    I got en error saying “Source file ‘..\..\..\..\..\..\..\..\..\..\..\user\AppData\Local\Temp\{7CAB0A87-6235-4FF3-9BF3-45C2EB48610C}\Architecture\DocHookups7604\266198272\test_hello\Source\test_hello\ThisDocument.Designer.cs’ could not be found (CS2001)”
    Is there any setting that I need to do before create a revit macro?

    thank you.

      • Hi Harry,

        I have created a new revit template and created a new doument macro in the template and I am getting the same error:
        1. Source file ‘..\..\..\..\..\..\..\..\..\..\..\User\AppData\Local\Temp\{A463023E-E99A-4D31-B3FC-6C23FA5CCCD9}\Architecture\DocHookups11516\272751872\SDPHello\Source\SDPHello\ThisDocument.Designer.cs’ could not be found (CS2001)

        2. Source file ‘..\..\..\..\..\..\..\..\..\..\..\User\AppData\Local\Temp\{A463023E-E99A-4D31-B3FC-6C23FA5CCCD9}\Architecture\DocHookups11516\272751872\SDPHello\Source\SDPHello\ThisDocument.cs’ could not be found (CS2001)

        3. Source file ‘..\..\..\..\..\..\..\..\..\..\..\User\AppData\Local\Temp\{A463023E-E99A-4D31-B3FC-6C23FA5CCCD9}\Architecture\DocHookups11516\272751872\SDPHello\Source\SDPHello\Properties\AssemblyInfo.cs’ could not be found (CS2001)

        • I’m experiencing the same problem. It appears that SharpDevelop creates files at Temp Folder, and cannot find them later.
          I’m still trying to figure out what to do, without success. Oddly, I’ve started the same procedure at my colleague’s computer and it has returned no errors.
          Abby, have you found a solution?

  3. Thankyou very much Joao, i had the same problem, but when i created application macro its working..kindly post your comments if you get solution for creating document macro..Thanks

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s