Postable Commands (ID_EDIT_MOVE) with Command Binding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to Post the Move command and have some code that needs to execute both prior to and post execution.
Here's some code.
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
UIApplication uiApp = commandData.Application;
UIDocument uiDoc = commandData.Application.ActiveUIDocument;
Document doc = uiDoc.Document;
// select all relevant elements
//Registry.CurrentInstance.SelectAll(uiDoc);
RevitCommandId moveId = RevitCommandId.LookupPostableCommandId(PostableCommand.Move);
if (uiApp.CanPostCommand(moveId)) uiApp.PostCommand(moveId);
}
I am able to Post the move command with just the above code perfectly fine, but as soon as I bind to pre/post-execution, the command fails to run.
I do the command binding registration in my entry point. And registration appears to be successful.
public class App : IExternalApplication
{
public static bool IsInternalChange { get; set; }
public Result OnStartup(UIControlledApplication application)
{
application.ControlledApplication.ApplicationInitialized += OnApplicationInitialised;
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
return Result.Succeeded;
}
private void OnApplicationInitialised(object? sender, ApplicationInitializedEventArgs e)
{
Application? app = sender as Application;
UiApplication = new UIApplication(app);
RegisterMoveCommand(UiApplication);
}
private void RegisterMoveCommand(UIApplication uiApp)
{
var moveId = RevitCommandId.LookupPostableCommandId(PostableCommand.Move);
if (moveId == null || !moveId.CanHaveBinding || moveId.HasBinding) return moveId;
AddInCommandBinding binding = uiApp.CreateAddInCommandBinding(moveId);
binding.BeforeExecuted += OnMoveBeforeExecuted;
binding.Executed += OnMoveExecuted;
return moveId;
}
private void OnMoveBeforeExecuted(object? sender, BeforeExecutedEventArgs e)
{
IsInternalChange = true;
}
private void OnMoveExecuted(object? sender, ExecutedEventArgs e)
{
IsInternalChange = false;
}
}
The events `OnMoveBeforeExecuted` and `OnMoveExecuted` are both fired. But the command itself does not run.
No Exceptions are thrown.
The command is not added to the undo stack.
Nothing is revealed in the journal as to why the command does not execute..
'E 05-Sep-2025 09:59:26.419; 0:<
' [Jrn.Tooltip] Rvt.Attr.Tooltip.CommandID: ID_EDIT_MOVE Rvt.Attr.Tooltip.ElapsedTime: 0.1529315 Rvt.Attr.Tooltip.Enabled: True Rvt.Attr.Tooltip.IsFirst: False Rvt.Attr.Tooltip.Key: ID_EDIT_MOVE Rvt.Attr.Tooltip.Progressive: True Rvt.Attr.Tooltip.Progressive.Delay: 2
'E 05-Sep-2025 09:59:26.532; 0:<
Jrn.Command "Ribbon" , "Move selected objects or their copies , ID_EDIT_MOVE"
Even just simply hitting the move button after doing this does not yield any result either.
I've checked the flags. The Command can have a binding, and there are no bindings attached already. I tried only registering the prior or the latter, the issue still persists..
What am I missing here?