That's annoying that the EditorInteractionType.Dismiss does not work...
I kinda found a workaround by deselecting all the elements in the ViewActivating and selecting after the view finish to change in the ViewActivated.
At least Revit does not break anymore, but I don't know if that approach gonna have some issue when you have too many elements selected and change the view, probably would make more sense to only do that if selection have only groups.
Here is the basic code.
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using Autodesk.Revit.UI.Selection;
using System.Collections.Generic;
namespace RevitAddin.Revit
{
public class AppView : IExternalApplication
{
public Result OnStartup(UIControlledApplication application)
{
application.ViewActivating += Application_ViewActivating;
application.ViewActivated += Application_ViewActivated;
return Result.Succeeded;
}
public Result OnShutdown(UIControlledApplication application)
{
application.ViewActivating -= Application_ViewActivating;
application.ViewActivated -= Application_ViewActivated;
return Result.Succeeded;
}
ICollection<ElementId> elementIds;
private void Application_ViewActivating(object sender, Autodesk.Revit.UI.Events.ViewActivatingEventArgs e)
{
var uiapp = sender as UIApplication;
UIDocument uidoc = uiapp.ActiveUIDocument;
Selection selection = uidoc.Selection;
elementIds = selection.GetElementIds();
selection.SetElementIds(new ElementId[] { });
}
private void Application_ViewActivated(object sender, Autodesk.Revit.UI.Events.ViewActivatedEventArgs e)
{
var uiapp = sender as UIApplication;
UIDocument uidoc = uiapp.ActiveUIDocument;
Selection selection = uidoc.Selection;
selection.SetElementIds(elementIds);
elementIds = new ElementId[] { };
}
}
}
Maybe if you use the ViewActivating event to force your DockablePane to lose focus, maybe that do the trick.