So I have it in the Application level.
1. On Startup Biding and capturing the application for later use.
public Result OnStartup(UIControlledApplication application)
{
ControlID.application = application;
AddCommandBindings(application, "ID_INPLACE_COMPONENT");
return Result.Succeeded;
}
2. Add the Command Binding and the Method to call when it captures the command.
private Result AddCommandBindings(UIControlledApplication application, string name)
{
RevitCommandId rCommandId = RevitCommandId.LookupCommandId(name);
if (rCommandId.CanHaveBinding)
{
try
{
if (name == "ID_INPLACE_COMPONENT")
{
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(this.DisableCommand);
}
}
catch
{
MessageBox.Show("Command " + name + " is already bound.");
}
}
return Result.Succeeded;
}
3. This is the Method the CommandBinding calls when fired
private void DisableCommand(object sender, ExecutedEventArgs args)
{
ControlID.postCommand = args.CommandId.Name;
using (Forms.RevitPostCommandForm rpc = new Forms.RevitPostCommandForm())
{
if (rpc.ShowDialog() == DialogResult.OK)
{
UIDocument uiDoc = new UIDocument(args.ActiveDocument);
uiDoc.Application.RemoveAddInCommandBinding(args.CommandId);
uiDoc.Application.PostCommand(args.CommandId);
ControlID.application.Idling += new EventHandler<IdlingEventArgs>(InPlaceComponent_Idling);
}
}
}
4. Use the associated idling event to Add the command binding back after it has fired the second time.
private void InPlaceComponent_Idling(object sender, IdlingEventArgs args)
{
AddCommandBindings(ControlID.application, "ID_INPLACE_COMPONENT");
ControlID.application.Idling -= InPlaceComponent_Idling;
}
public static class ControlID
{
public static UIControlledApplication application { get; set; }
}
Sean Page, AIA, NCARB, LEED APPartner, Computational Designer, Architect