private static void ShutdownRevitHostOnce(object sender, IdlingEventArgs idlingEventArgs) { var uiApplication = DocumentManager.Instance.CurrentUIApplication; uiApplication.Idling -= ShutdownRevitHostOnce; RevitDynamoModel.ShutdownRevitHost(); }
public SiteLocation(WorkspaceModel workspaceModel) : base(workspaceModel) { OutPortData.Add(new PortData("Location", "The location of the current Revit project.")); RegisterAllPorts(); Location = DynamoUnits.Location.ByLatitudeAndLongitude(0.0, 0.0); ArgumentLacing = LacingStrategy.Disabled; model = (RevitDynamoModel)workspaceModel.DynamoModel; model.RevitDocumentChanged += model_RevitDocumentChanged; model.RevitServicesUpdater.ElementsModified += RevitServicesUpdater_ElementsModified; Update(); }
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements) { HandleDebug(commandData); InitializeCore(commandData); try { IdlePromise.ExecuteOnIdleAsync( delegate { // create core data models revitDynamoModel = InitializeCoreModel(commandData); dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); // show the window InitializeCoreView().Show(); TryOpenWorkspaceInCommandData(commandData); SubscribeViewActivating(commandData); }); // Disable the Dynamo button to prevent a re-run DynamoRevitApp.DynamoButton.Enabled = false; } catch (Exception ex) { // notify instrumentation InstrumentationLogger.LogException(ex); StabilityTracking.GetInstance().NotifyCrash(); MessageBox.Show(ex.ToString()); DynamoRevitApp.DynamoButton.Enabled = true; return Result.Failed; } return Result.Succeeded; }
private static DynamoViewModel InitializeCoreViewModel(RevitDynamoModel revitDynamoModel) { var vizManager = new RevitVisualizationManager(revitDynamoModel); var viewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = revitDynamoModel, VisualizationManager = vizManager, WatchHandler = new RevitWatchHandler(vizManager, revitDynamoModel.PreferenceSettings) }); viewModel.RequestAuthentication += SingleSignOnManager.RegisterSingleSignOn; revitDynamoModel.ShuttingDown += (drm) => IdlePromise.ExecuteOnShutdown( delegate { if (null != DocumentManager.Instance.CurrentDBDocument) { TransactionManager.Instance.EnsureInTransaction(DocumentManager.Instance.CurrentDBDocument); var keeperId = vizManager.KeeperId; if (keeperId != ElementId.InvalidElementId) { DocumentManager.Instance.CurrentUIDocument.Document.Delete(keeperId); } TransactionManager.Instance.ForceCloseTransaction(); } }); return viewModel; }
/// <summary> /// This method (Application.Idling event handler) is called exactly once /// during the creation of Dynamo Revit plug-in. It is in this call both /// DynamoScheduler and its RevitSchedulerThread objects are created. All /// other AsyncTask beyond this point are scheduled through the scheduler. /// </summary> /// private static void OnRevitIdleOnce(object sender, IdlingEventArgs e) { // We only need to initialize this once, unregister. extCommandData.Application.Idling -= OnRevitIdleOnce; // create core data models revitDynamoModel = InitializeCoreModel(extCommandData); dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); // show the window InitializeCoreView().Show(); TryOpenWorkspaceInCommandData(extCommandData); SubscribeViewActivating(extCommandData); }
/// <summary> /// Executes after Dynamo closes. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private static void OnDynamoViewClosed(object sender, EventArgs e) { var view = (DynamoView)sender; revitDynamoModel.RevitServicesUpdater.Dispose(); DocumentManager.OnLogError -= revitDynamoModel.Logger.Log; view.Dispatcher.UnhandledException -= Dispatcher_UnhandledException; view.Closed -= OnDynamoViewClosed; DocumentManager.Instance.CurrentUIApplication.ViewActivating -= OnApplicationViewActivating; AppDomain.CurrentDomain.AssemblyResolve -= Analyze.Render.AssemblyHelper.ResolveAssemblies; // KILLDYNSETTINGS - this is suspect revitDynamoModel.Logger.Dispose(); DynamoRevitApp.DynamoButton.Enabled = true; revitDynamoModel = null; }
private static DynamoViewModel InitializeCoreViewModel(RevitDynamoModel revitDynamoModel) { var vizManager = new RevitVisualizationManager(revitDynamoModel); var viewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = revitDynamoModel, VisualizationManager = vizManager, WatchHandler = new RevitWatchHandler(vizManager, revitDynamoModel.PreferenceSettings) }); revitDynamoModel.PackageManagerClient.RequestAuthentication += SingleSignOnManager.RegisterSingleSignOn; #if ENABLE_DYNAMO_SCHEDULER revitDynamoModel.ShutdownStarted += (drm) => { var uiApplication = DocumentManager.Instance.CurrentUIApplication; uiApplication.Idling += DeleteKeeperElementOnce; }; #else revitDynamoModel.ShutdownStarted += (drm) => IdlePromise.ExecuteOnShutdown(DeleteKeeperElement); #endif return viewModel; }
public new static RevitDynamoModel Start() { return(RevitDynamoModel.Start(new StartConfiguration())); }