I had a hunch the RevitCommandEndedMonitor would work with the RequestViewChange() method as well and curiosity got the better of me. Sure enough, it worked!
[Transaction(TransactionMode.Manual)] [Regeneration(RegenerationOption.Manual)] public class TestCommand : IExternalCommand { private UIApplication _uiApp; public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { _uiApp = commandData.Application; TaskDialog.Show("Switch To Sheet Example", "I'm doing things before switching to the sheet."); var sheet = Get your ViewSheet <<thisDoc.GetElement(My.Settings.Item("LastActiveView"))>> var switchToSheetMonitor = new RevitCommandEndedMonitor(_uiApp); switchToSheetMonitor.CommandEnded += ContinueAfterSwitchToSheet; _uiApp.ActiveUIDocument.RequestViewChange(sheet); return Result.Succeeded; } private void ContinueAfterSwitchToSheet(object sender, EventArgs e) { _uiApp.ActiveUIDocument.RefreshActiveView(); TaskDialog.Show("Switch To Sheet Example", $"I just switched to {_uiApp.ActiveUIDocument.ActiveGraphicalView.ViewName}"); } }
If you use it this way I'd do two things first, rename the RevitCommandEndedMonitor to something like RequestEndedMonitor, and second, test the s**t out of it.
Note: Edited to remove errant command result handling.