So you wrote a super useful Revit macro that automates some really tedious tasks in Revit. You’ve saved yourself at least twenty hours on your last project. Now you want to use that same macro on your current project. How can you copy the macro code over to another RVT file?
Unfortunately there’s no magic “copy macro” button (at least not yet). Because the macro is embedded in the Revit project file, it is not obvious how to copy that macro to another file. Here are three methods I use to copy my Revit macros to other project files:
1. Cut and Paste the Macro Code
Open the Revit project file containing the macro you want to copy as well as the file you want to copy the macro into. Go to the Macro Manager (Manage > Macro Manager) and edit the existing macro to open SharpDevelop.
In the existing macro, select the code you want to copy then go to Edit > Copy or press Control + C to copy the code to the clipboard.
In the file you want to copy the macro into, create a new module and macro of the same name. Make sure you select the same programming language as the existing macro.
In the new SharpDevelop window, paste the code from the existing macro into the new macro. Build your solution to ensure it works properly then save the new macro file.
This method works great for simple macros that do not use forms or multiple class files.
2. Export the Macro Code from SharpDevelop
If your macro uses forms or has multiple class or module files, you can use this method to export all the associated files.
Open the Revit project file containing the macro you want to copy. Go to Manage > Macro Manager and edit the existing macro to open SharpDevelop.
In the “Projects” window of SharpDevelop, select the file that contains the code you want to copy.
Go to File > Save As to export the selected code file.
Create a new module in the file you want to copy the macro into. Make sure you set the language to the same as the macro you want to copy. This will open a new session of SharpDevelop.
In the new SharpDevelop window, select the module name in the “Projects” window, right-click and select Add > Existing.
Browse to the location where you save the code file and import it.Build the code to ensure it’s working correctly.
If the macro you’re copying has multiple classes or forms, you’ll need to export and import each file individually.
3. Import the Source Code from Temp Folder
Don’t feel like importing and exporting your macro’s various files? Use this method to import a whole folder of code files.
Whenever you open a macro in SharpDevelop, the source code is saved to a temporary folder on the local computer. You can access this folder by selecting the macro in the SharpDevelop “Projects” window, right-clicking and choosing “Open Folder in Explorer”.
Because it is a temporary folder, the folder name is going to be long and (really) obtuse.
Once you know the folder path of the existing macro, create a new module in the file where you want to copy the macro. Again, make sure you set the language to the same as the macro you want to copy.
In the new SharpDevelop window, select the module name in the “Projects” window, right-click and select Add > Existing Folder. Browse to the existing macro’s folder. Unfortunately you can’t just cut and paste the folder location, you need to browse to it directly.
Once you’ve found the folder, click “OK” to import it into your new macro. Choose “Copy” to copy the folder to the target macro location.
This will likely create multiple instances of some objects in the new macro. Delete the existing version of “ThisDocument” as well as the “Properties” folder. Build the macro to ensure it compiles correctly.
What About Application Macros?
The three methods outlined above work great for document macros that are saved in RVT files but what about application macros? Can you copy a document macro as an application macro?
An application macro operates at the application level. When you create an application macro, you’ll see that the macro code creates a “ThisApplication” class rather than “ThisDocument”. You can use any of the methods above to copy a document macro to your application macros, however, you will need to make some modifications to your code.
Check out the video below for a step-by-step guide to copying a project macro to your application macros.
Conclusion
Copying a macro to a new RVT file or application macro is not an automatic process but it can be accomplished using the steps outlined above. As long as you are systematic, you should not have too much difficulty transferring your macros.
If you know of another method to copy macros, please let me know in the comments below! I’m always looking for an easier method.
You can open the revit with macros along with the your current project go to macro manager and run from there, it will run in the current project that is how I am doing it in Revit 2014
Yes, that method definitely works. I’ve found that some people, however, like to add macros from their project files into their application macro file. This requires a little work, as indicated in the post above, but doesn’t require you to open the individual project files to run the macros. Instead, the macros are always available to you.
Please we need a macro to export all schedules to excel file or csv file in one click
and we are waiting your course about programming Revit with VB.net
thanks sir
Yasser – I’ll take a look at that request. Good suggestion! Also, I’m working on the course currently. Look for more information in the next month.
This is sending me a lot of errors trying to copy the Convert DWG to Revit Macro to Application Macros.
Build started.
Compiling ArchSmarter
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterConvertDWGToRVT.vb(39,26) : Error BC30002: El tipo ‘Windows.Forms.ToolTip’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterConvertDWGToRVT.vb(211,17) : Error BC30002: El tipo ‘Windows.Forms.OpenFileDialog’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterConvertDWGToRVT.vb(222,24) : Error BC30456: ‘Forms’ no es un miembro de ‘Windows’.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterConvertDWGToRVT.vb(315,18) : Error BC30002: El tipo ‘Windows.Forms.SaveFileDialog’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterThisApplication.vb(49,13) : Error BC30269: ‘Public Sub ConvertDWGToRVT()’ tiene varias definiciones con signaturas idénticas.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterfrmConvertWithLS.vb(44,26) : Error BC30002: El tipo ‘Windows.Forms.ToolTip’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterfrmConvertWithLayers.vb(39,26) : Error BC30002: El tipo ‘Windows.Forms.ToolTip’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterfrmConvertWithLayers.vb(211,17) : Error BC30002: El tipo ‘Windows.Forms.OpenFileDialog’ no está definido.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterfrmConvertWithLayers.vb(222,24) : Error BC30456: ‘Forms’ no es un miembro de ‘Windows’.
C:ProgramDataAutodeskRevitMacros2016RevitAppHookupArchSmarterSourceArchSmarterfrmConvertWithLayers.vb(315,18) : Error BC30002: El tipo ‘Windows.Forms.SaveFileDialog’ no está definido.
Build failed. (00:00:01.1371137)
Any Help so far?
Martin – It could be that there are no references to the Windows.Forms library in the new macro. Try creating a new form. This will automatically add the library to the project. Let me know if you need help doing this.
Michael
Hi Michael,
I’m attempting to copy your Macro for converting DWGs to Lines from the file provided in 2015 to a standard detail project file in 2014.
I’ve tried copying the code in a couple of ways following the above instructions but I’m still getting the message below. I’m new to Macros today and I’ll admit I’m stumped. Any idea why this isn’t working?
———————————————————————————————————
Revit failed to execute ConvertDWGtoDetailLines.
A problem has been detected.
System.NullReferenceException: Object reference not set to an instance of an object.
at MacroModule.executeMacro_(MacroModule* ,AString* macroName)
at MacroModule.executeMacro(MacroModule* ,AString*)
at
UIMacroGeneralManager.runMacro(UIMacroGeneralManager* , MacroModule*pModule, AString* macroName)
Hi Kathleen,
That macro doesn’t work in Revit 2014. There’s one function in the macro that I simply can’t get to work in versions before 2015. I’ve contacted Autodesk but no luck. The Revit API changes from version to version so I suspect some functionality was added in 2015 that opened up this part of the software. Sorry about that.
Michael
Hi Michael,
I did manage to successfully copy it to a different 2015 project so I thought it might be something to do with the version change. I was hoping it was just something that needed tweaked that I couldn’t find. 236 CAD details to bring into Revit, I think I might just do it in 2015 instead!
Thanks for your quick response.
Kathleen
Hi Michael,
Im trying to convert the “DWG to drafting view macro” to an application macro using the method in the video. The build works fine with no errors but when I run the macro the select files button does nothing. any ideas? Im using v2016
Scott – Did you copy the code over from the “frmImportDWG.vb”? There’s an action associated with the button that launches the OpenFileDialog. In your application macro, click on “frmImportDWG” then click the “Source” tab at the bottom of the code window. Make sure there’s a function called “Button1click”. Also, when you click on the “Design” tab, do you see a yellow bar containing “openFileDialog1”?
Mr. Kilkelly,
I have the same problem as Scott. I do have the Button1click function in the frmImportDWG. I also have the openFileDialog1 in the yellow bar. However, I still have the same errors that Scott was encountering. Any other suggestions? It would be greatly appreciated. Thank you.
Hi Michael,
I’ve just gotten into using Macros and they seem to be working great, I definitely plan to use them when working on projects.
I tried the different methods you described to copy the macros into my office Revit Project Template but does it does not seem to work.
Have you found another way to do this, or could a macro help in transferring existing macros between revit files?
Thanks again.
Hi Michael,
I’m trying to add your DWG to RVT lines macro into my template file and everything seems to run smoothly up until I build the code. The Code builds successfully in SharpDevelop but when I switch back to Revit I get the following error:
Loading the macro failed. Rebuilding the module may resolve this issue.
Am I missing a step?
Hello,
Thank you for the tutorial.
For the form you can copy it more easily. I have done the following successfully in the past. First create a form in the new macro with the same name and paste the code from the source macro (so far it’s as you did). Now in the source macro, go to the project browser and click the + symbol in the form to expand it, there you will see an additional code that defines the graphical controls of the macro. Just copy and paste that code in the new macro (also expanding with the +) and voila!