Unpin Command Binding - Ribbon vs Toggle
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
After a string of unfortunate events, I am trying to bind to the Unpin command to ask users are they sure they want to unpin the element. This is working great when I bind to the "ID_UNLOCK_ELEMENTS" command.
However, if the element is locked, and then a users toggles it with the visual "pin" in the view, the bound event does not fire. So, I think looked and found that the Command Id for that was actually different. So, I check and it said that it allows binding as well, bound to it using the same method and event, however nothing fires when the toggle is clicked.
Anyone have any idea why it would be acting different?
startup:
AddCommandBindings(application, "ID_UNLOCK_ELEMENTS");
AddCommandBindings(application, "ID_PIN_CTRL_TOGGLE");
Method:
private void AddCommandBindings(UIControlledApplication application, string name)
{
RevitCommandId rCommandId = RevitCommandId.LookupCommandId(name);
if(rCommandId.CanHaveBinding)
{
try
{
switch(name)
{
case "ID_UNLOCK_ELEMENTS":
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(DisableCommand);
break;
case "ID_PIN_CTRL_TOGGLE":
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(UnPinToggle);
break;
case "ID_INPLACE_COMPONENT":
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(DisableCommand);
break;
case "ID_FILE_IMPORT":
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(DisableCommand);
break;
case "ID_WORKSETS_RELOAD_LATEST":
application.CreateAddInCommandBinding(rCommandId).Executed += new EventHandler<ExecutedEventArgs>(ReloadLatestUpdaters);
break;
default:
break;
}
}
catch
{
MessageBox.Show("Command " + name + " is already bound.");
}
}
}
Event (Essentially just presents a dialog tot he user with the command info and why they shouldn't be doing what they are doing, general utility):
private void DisableCommand(object sender, ExecutedEventArgs args)
{
using(Forms.RevitPostCommandForm rpc = new Forms.RevitPostCommandForm(args.CommandId))
{
if(rpc.ShowDialog() == DialogResult.OK)
{
ControlParams.postCommand = args.CommandId.Name;
UIDocument uiDoc = new UIDocument(args.ActiveDocument);
uiDoc.Application.RemoveAddInCommandBinding(args.CommandId);
ControlParams.application.Idling += new EventHandler<IdlingEventArgs>(PostCommand_Idling);
idleCheck = false;
uiDoc.Application.PostCommand(args.CommandId);
}
}
}