<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Revit 2017 Add-In using Macro API in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6602250#M62602</link>
    <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have deployed and altered the macro to use my own placeholder file instead, and implemented the macro as per&amp;nbsp;Jeremy Tammik's post, described here &lt;A title="Installing a Macro and Closing the Active Document" href="http://thebuildingcoder.typepad.com/blog/2012/12/closing-the-active-document.html" target="_self"&gt;Installing a Macro and Closing the Active Document&lt;/A&gt;. Thanks Jeremy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Assemblies used...&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier"&gt;RevitAPI
RevitAPIUI
RevitAPIMaros
RevitAPIUIMacros&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Namespaces used...&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;FONT size="2"&gt;using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Macros;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Macros;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Code Segment...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;
		}
	}
}
...
...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Zach.&lt;/P&gt;</description>
    <pubDate>Wed, 05 Oct 2016 08:40:17 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2016-10-05T08:40:17Z</dc:date>
    <item>
      <title>Revit 2017 Add-In using Macro API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6602250#M62602</link>
      <description>&lt;P&gt;Hi All&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have deployed and altered the macro to use my own placeholder file instead, and implemented the macro as per&amp;nbsp;Jeremy Tammik's post, described here &lt;A title="Installing a Macro and Closing the Active Document" href="http://thebuildingcoder.typepad.com/blog/2012/12/closing-the-active-document.html" target="_self"&gt;Installing a Macro and Closing the Active Document&lt;/A&gt;. Thanks Jeremy!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Assemblies used...&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier"&gt;RevitAPI
RevitAPIUI
RevitAPIMaros
RevitAPIUIMacros&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Namespaces used...&lt;/P&gt;&lt;PRE&gt;&lt;FONT face="courier new,courier" size="2"&gt;&lt;FONT size="2"&gt;using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.Macros;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Macros;&lt;/FONT&gt;&lt;/FONT&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Add-In Code Segment...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;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;
		}
	}
}
...
...&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Zach.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 08:40:17 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6602250#M62602</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-05T08:40:17Z</dc:date>
    </item>
    <item>
      <title>Re: Revit 2017 Add-In using Macro API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6604234#M62603</link>
      <description>&lt;P&gt;I haven't tried the process of launching a macro from an addin. But I have&amp;nbsp;accomplished the same thing (loading placeholder model, then closing other model) using this method&amp;nbsp;&lt;A href="http://thebuildingcoder.typepad.com/blog/2010/10/closing-the-active-document-and-why-not-to.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2010/10/closing-the-active-document-and-why-not-to.html&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Steps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) Open placeholder model document&lt;/P&gt;&lt;P&gt;2) Close the original model document&lt;/P&gt;&lt;P&gt;3) Activate the new thread to send the Ctrl-F4 to the placeholder model (assuming no other models open)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Oct 2016 22:22:26 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6604234#M62603</guid>
      <dc:creator>Troy_Gates</dc:creator>
      <dc:date>2016-10-05T22:22:26Z</dc:date>
    </item>
    <item>
      <title>Re: Revit 2017 Add-In using Macro API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6604727#M62604</link>
      <description>&lt;P&gt;Hi Troy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thx for the response.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you execute your macro manually via the Revit UI then, by accessing the macro manager?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS. Noticed one can only close the last active document via the Revit UI, either using the Close menu option or by a custom created function like&lt;/P&gt;&lt;P&gt;a macro or external command.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS2. The last active document cannot by closed via API, thus swopping it out&amp;nbsp;with a placeholder one and making it the new active document will enable one to close the previous active one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS3. I have deployed&amp;nbsp;a macro to perform the document swop out, works fine when executed from the Revit UI, but cannot get it to work executed from an add-in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS4. I then created a custom external command containing the logic to also perform a document swop out, also works fine when executed from the Revit UI, but does not work when executed from my add-in.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;WiIl create a new post for that as it does not involve a macro anymore.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Zach&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2016 06:56:56 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6604727#M62604</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-06T06:56:56Z</dc:date>
    </item>
    <item>
      <title>Re: Revit 2017 Add-In using Macro API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6606384#M62605</link>
      <description>&lt;P&gt;I am using it via an addin and not in a macro.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1) External Command that loads form that batch open/closes documents. Once the form has completed running the batch process (Steps 2 and 3 below), it starts the ThreadPool.QueueUserWorkItem and calls the method ClosePlaceHolder.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;    public class BatchProcess : IExternalCommand
    {
        public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elementSet)
        {
            try
            {
                BatchForm batchForm = new BatchForm(commandData.Application);
                if (batchForm.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    ThreadPool.QueueUserWorkItem(new WaitCallback(ClosePlaceholder));
                }
                
                return Result.Succeeded;
            }
            catch(Exception e)
            {
                TaskDialog.Show("Error", e.Message);
                return Result.Failed;
            }
        }

        private void ClosePlaceholder(object state)
        {
            try
            {
                SendKeys.SendWait("^{F4}");
            }
            catch
            {

            }
        }

    }&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;2) Some code from my batch process&amp;nbsp;that opens placeholder model&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;uiapp.OpenAndActivateDocument(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + @"\Placeholder.rvt");
Document placeholderDoc = uiapp.ActiveUIDocument.Document;&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;3) During the batch process, I open and close models using code like this. Once the batch is done I only have the Placeholder.rvt model open.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Document doc = uiapp.Application.OpenDocumentFile(modelPathOpen, openOptions);

doc.Close(false); // I use false to save because I already saved the model using doc.SaveAs() before closing&lt;BR /&gt;&lt;BR /&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 06 Oct 2016 18:44:32 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6606384#M62605</guid>
      <dc:creator>Troy_Gates</dc:creator>
      <dc:date>2016-10-06T18:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Revit 2017 Add-In using Macro API</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6607473#M62606</link>
      <description>&lt;P&gt;Hi Troy&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did something similar, created 2&amp;nbsp;external commands.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The one just sends the F4 key stroke like yours, while the other compares the current active document with that of my placeholder file - if a match is not found the current active document is swopped out with the placeholder file and the previous active document closed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both external commands working fine using the Revit UI, but not when called from my addin.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I use the approach below to attempt to call the external command from my addin...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Below is the manifest of my custom external command addin:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&amp;gt;
&amp;lt;RevitAddIns&amp;gt;
	&amp;lt;AddIn Type="Command"&amp;gt;
		&amp;lt;Name&amp;gt;Document Swop&amp;lt;/Name&amp;gt; 
		&amp;lt;Description&amp;gt;Swop the active document&amp;lt;/Description&amp;gt;
		&amp;lt;Text&amp;gt;Document Swop&amp;lt;/Text&amp;gt;
    		&amp;lt;Assembly&amp;gt;C:\My Addins\DocumentSwop.dll&amp;lt;/Assembly&amp;gt; 
    		&amp;lt;AddInId&amp;gt;21A8C920-ED49-434A-AACD-176784316B93&amp;lt;/AddInId&amp;gt;
    		&amp;lt;FullClassName&amp;gt;AddIns.DocumentSwop&amp;lt;/FullClassName&amp;gt;
		&amp;lt;VendorId&amp;gt;Vendor Name&amp;lt;/VendorId&amp;gt;    
		&amp;lt;VendorDescription&amp;gt;Vendor Desc&amp;lt;/VendorDescription&amp;gt;
  	&amp;lt;/AddIn&amp;gt; 
&amp;lt;/RevitAddIns&amp;gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The GUID represents the&amp;nbsp;external command's manifest id, as seen above&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;private static string comIdCommandDocumentSwop = "21A8C920-ED49-434A-AACD-176784316B93";     &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I then try to execute the external command by looking up its command id and&amp;nbsp;execute it using the PostCommand method.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Having no luck as the command id returned is null, thus the command not executed.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;try
{
	addinId = RevitCommandId.LookupCommandId(comIdCommandDocumentSwop);
}
catch (Exception ex)
{
	Misc.WriteLog(ex.Message);
}

if (addinId != null)
{
	try
	{
		uiapp.PostCommand(addinId);
	}
	catch (Exception ex)
	{
		Misc.WriteLog(ex.Message);
	}
}&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Not sure if this is the correct&amp;nbsp;approach, any ideas?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Zach.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Oct 2016 07:43:02 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/revit-2017-add-in-using-macro-api/m-p/6607473#M62606</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2016-10-07T07:43:02Z</dc:date>
    </item>
  </channel>
</rss>

