This is the complete macro to run a Postable Command. To recreate this example, do the following:
The code:
/*
* Created by SharpDevelop
* Date: 8/26/2018
* Time: 8:08 PM
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using Autodesk.Revit.UI;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
using System.Linq;
namespace Pcommand
{
[Autodesk.Revit.Attributes.Transaction(Autodesk.Revit.Attributes.TransactionMode.Manual)]
[Autodesk.Revit.DB.Macros.AddInId("7969AF66-0C32-4AD0-B0C8-73048393937A")]
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);
}
#endregion
public void Pcommand()
{
Document doc = this.ActiveUIDocument.Document;
UIApplication uiapp = new UIApplication(Application);
UIDocument uidoc = this.ActiveUIDocument;
try
{
RevitCommandId id = RevitCommandId.LookupPostableCommandId(PostableCommand.PlaceAComponent);
if (id != null)
{
TaskDialog.Show("Test", "Found ID");
uiapp.PostCommand(id);
}
}
catch
{
TaskDialog.Show("Test", "error");
}
}
}
}