PostCommandId equals UNDO

PostCommandId equals UNDO

Anonymous
Not applicable
769 Views
2 Replies
Message 1 of 3

PostCommandId equals UNDO

Anonymous
Not applicable

Hello friends I have big question. When I want to sign PostcommandId equals UNDO = 33032, I have an exception:

"The Revit command id cannot be assigned a command binding." but when I sign another command there is not happen any exceptions. Why is happened to this command? And how to do it right? This is my code:

First decision:

 

RevitCommandId commandId = RevitCommandId.LookupPostableCommandId(PostableCommand.Undo);
AddInCommandBinding importBinding = a.CreateAddInCommandBinding(commandId); (An exception occurs here)
importBinding.BeforeExecuted += new EventHandler<Autodesk.Revit.UI.Events.BeforeExecutedEventArgs>(Undo);

 

Second  decision: 

 

RevitCommandId commandId = RevitCommandId.LookupCommandId("ID_BUTTON_UNDO");
AddInCommandBinding importBinding = a.CreateAddInCommandBinding(commandId); (An exception occurs here)
importBinding.BeforeExecuted += new EventHandler<Autodesk.Revit.UI.Events.BeforeExecutedEventArgs>(Undo);

 

0 Likes
Accepted solutions (1)
770 Views
2 Replies
Replies (2)
Message 2 of 3

jeremytammik
Autodesk
Autodesk

Maybe Undo is an exception, intentionally?

 

What does CanPostCommand report for Undo?

 

 



Jeremy Tammik
Developer Technical Services
Autodesk Developer Network, ADN Open
The Building Coder

0 Likes
Message 3 of 3

Sean_Page
Collaborator
Collaborator
Accepted solution

I would suggest that you check to make sure that it can have a binding before trying to add an event handler.

 

if(commandId.CanHaveBinding)
{
    AddInCommandBinding importBinding = a.CreateAddInCommandBinding(commandId);
}
Sean Page, AIA, NCARB, LEED AP
Partner, Computational Designer, Architect