Message 1 of 5
Revit 2017 Add-In using Macro API
Not applicable
10-05-2016
01:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi All
I want to execute an existing macro from my custom add-in, but having issues with the macro assemblies to resolve the MacroManager classes and related objects.
I have deployed and altered the macro to use my own placeholder file instead, and implemented the macro as per Jeremy Tammik's post, described here Installing a Macro and Closing the Active Document. Thanks Jeremy!
As per the post, it seems like one have to add additional assemblies for RevitAPIMacros and RevitAPIUIMacros. I have done so but still unable to compile successfully?
Add-In Assemblies used...
RevitAPI RevitAPIUI RevitAPIMaros RevitAPIUIMacros
Add-In Namespaces used...
using Autodesk.Revit.Attributes; using Autodesk.Revit.DB; using Autodesk.Revit.DB.Macros; using Autodesk.Revit.UI; using Autodesk.Revit.UI.Macros;
Add-In Code Segment...
bool bModuleFound = false;
bool bMacroFound = false;
Autodesk.Revit.DB.Macros.MacroManager macroMgr = null;
try
{
macroMgr = MacroManager.GetMacroManager(uiapp.Application);
foreach (Autodesk.Revit.DB.Macros.MacroModule module in macroMgr)
{
Misc.WriteLog(" Search for module UiClose...");
if (module.Name.Equals("UiClose"))
{
bModuleFound = true;
Misc.WriteLog(" Module UiClose found");
foreach (Autodesk.Revit.DB.Macros.Macro macro in module)
{
if (macro.Name.Equals("CloseActiveDocDemo"))
{
bMacroFound = true;
Misc.WriteLog(" Macro CloseActiveDocDemo found");
macro.Execute();
Misc.WriteLog(" Macro CloseActiveDocDemo executed");
break;
}
}
break;
}
}
}
...
...
Any help appreciated.
Regards,
Zach.