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 static DynamoRevitViewModel Start(StartConfiguration startConfiguration) { if (startConfiguration.DynamoModel == null) { startConfiguration.DynamoModel = RevitDynamoModel.Start(); } else { if (startConfiguration.DynamoModel.GetType() != typeof(RevitDynamoModel)) { throw new Exception("An instance of RevitDynamoModel is required to construct a DynamoRevitViewModel."); } } if (startConfiguration.Watch3DViewModel == null) { startConfiguration.Watch3DViewModel = HelixWatch3DViewModel.TryCreateHelixWatch3DViewModel( null, new Watch3DViewModelStartupParams(startConfiguration.DynamoModel), startConfiguration.DynamoModel.Logger); } if (startConfiguration.WatchHandler == null) { startConfiguration.WatchHandler = new DefaultWatchHandler(startConfiguration.DynamoModel.PreferenceSettings); } return(new DynamoRevitViewModel(startConfiguration)); }
public static DynamoRevitViewModel Start(StartConfiguration startConfiguration) { if (startConfiguration.DynamoModel == null) { startConfiguration.DynamoModel = RevitDynamoModel.Start(); } else { if (startConfiguration.DynamoModel.GetType() != typeof(RevitDynamoModel)) { throw new Exception("An instance of RevitDynamoViewModel is required to construct a DynamoRevitViewModel."); } } if (startConfiguration.VisualizationManager == null) { startConfiguration.VisualizationManager = new VisualizationManager(startConfiguration.DynamoModel); } if (startConfiguration.WatchHandler == null) { startConfiguration.WatchHandler = new DefaultWatchHandler(startConfiguration.VisualizationManager, startConfiguration.DynamoModel.PreferenceSettings); } return(new DynamoRevitViewModel(startConfiguration)); }
private void StartDynamo() { try { // create the transaction manager object TransactionManager.SetupManager(new AutomaticTransactionStrategy()); DynamoRevit.InitializeUnits(); var model = RevitDynamoModel.Start( new RevitDynamoModel.StartConfiguration() { StartInTestMode = true, DynamoCorePath = Path.GetFullPath(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\") }); this.ViewModel = DynamoViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = model }); // Because the test framework does not work in the idle thread. // We need to trick Dynamo into believing that it's in the idle // thread already. IdlePromise.InIdleThread = true; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
private static RevitDynamoModel InitializeCoreModel(ExternalCommandData commandData) { var prefs = PreferenceSettings.Load(); var corePath = Path.GetFullPath( Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\"); #if !ENABLE_DYNAMO_SCHEDULER return(RevitDynamoModel.Start( new RevitDynamoModel.StartConfiguration() { Preferences = prefs, DynamoCorePath = corePath, Context = GetRevitContext(commandData) })); #else return(RevitDynamoModel.Start( new RevitDynamoModel.StartConfiguration() { Preferences = prefs, DynamoCorePath = corePath, Context = GetRevitContext(commandData), SchedulerThread = new RevitSchedulerThread(commandData.Application) })); #endif }
public Result ExecuteCommand(DynamoRevitCommandData commandData) { var startupTimer = Stopwatch.StartNew(); HandleDebug(commandData); InitializeCore(commandData); try { extCommandData = commandData; shouldShowUi = CheckJournalForUiDisplay(extCommandData); isAutomationMode = CheckJournalForAutomationMode(extCommandData); UpdateSystemPathForProcess(); // create core data models revitDynamoModel = InitializeCoreModel(extCommandData); dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); revitDynamoModel.Logger.Log("SYSTEM", string.Format("Environment Path:{0}", Environment.GetEnvironmentVariable("PATH"))); // handle initialization steps after RevitDynamoModel is created. revitDynamoModel.HandlePostInitialization(); // show the window if (shouldShowUi) { InitializeCoreView().Show(); } TryOpenAndExecuteWorkspace(extCommandData); // Disable the Dynamo button to prevent a re-run DynamoRevitApp.DynamoButtonEnabled = false; Analytics.TrackStartupTime("DynamoRevit", startupTimer.Elapsed); } catch (Exception ex) { // notify instrumentation Analytics.TrackException(ex, true); MessageBox.Show(ex.ToString()); DynamoRevitApp.DynamoButtonEnabled = true; //If for some reason Dynamo has crashed while startup make sure the Dynamo Model is properly shutdown. if (revitDynamoModel != null) { revitDynamoModel.ShutDown(false); revitDynamoModel = null; } return(Result.Failed); } return(Result.Succeeded); }
static DynamoRevit() { idleActions = new List <Action>(); extCommandData = null; dynamoViewModel = null; revitDynamoModel = null; handledCrash = false; ModelState = RevitDynamoModelState.NotStarted; preLoadExceptions = new List <Exception>(); }
protected override void StartDynamo(TestSessionConfiguration testConfig) { try { UpdateSystemPathForProcess(); // create the transaction manager object TransactionManager.SetupManager(new AutomaticTransactionStrategy()); // Note that there is another data member pathResolver in base class // SystemTestBase. That pathResolver will be used only in StartDynamo // of the base class, here a local instance of pathResolver is used. // var revitTestPathResolver = new RevitTestPathResolver(); revitTestPathResolver.InitializePreloadedLibraries(); DynamoRevit.RevitDynamoModel = RevitDynamoModel.Start( new RevitDynamoModel.RevitStartConfiguration() { StartInTestMode = true, GeometryFactoryPath = DynamoRevit.GetGeometryFactoryPath(testConfig.DynamoCorePath), DynamoCorePath = testConfig.DynamoCorePath, PathResolver = revitTestPathResolver, Context = "Revit 2014", SchedulerThread = new TestSchedulerThread(), PackageManagerAddress = "https://www.dynamopackages.com", ExternalCommandData = new DynamoRevitCommandData(RevitTestExecutive.CommandData), ProcessMode = RevitTaskProcessMode }); Model = DynamoRevit.RevitDynamoModel; this.ViewModel = DynamoRevitViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = DynamoRevit.RevitDynamoModel, }); var vm3D = ViewModel.Watch3DViewModels.FirstOrDefault(vm => vm is RevitWatch3DViewModel); if (vm3D != null) { vm3D.Active = false; } // Because the test framework does not work in the idle thread. // We need to trick Dynamo into believing that it's in the idle // thread already. IdlePromise.InIdleThread = true; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }
private static DynamoViewModel InitializeCoreViewModel(RevitDynamoModel revitDynamoModel) { var viewModel = DynamoRevitViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = revitDynamoModel, WatchHandler = new RevitWatchHandler(revitDynamoModel.PreferenceSettings) }); return(viewModel); }
public Result ExecuteCommand(DynamoRevitCommandData commandData) { HandleDebug(commandData); InitializeCore(commandData); try { extCommandData = commandData; shouldShowUi = CheckJournalForUiDisplay(extCommandData); isAutomationMode = CheckJournalForAutomationMode(extCommandData); UpdateSystemPathForProcess(); // create core data models revitDynamoModel = InitializeCoreModel(extCommandData); dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); revitDynamoModel.Logger.Log("SYSTEM", string.Format("Environment Path:{0}", Environment.GetEnvironmentVariable("PATH"))); // handle initialization steps after RevitDynamoModel is created. revitDynamoModel.HandlePostInitialization(); // show the window if (shouldShowUi) { InitializeCoreView().Show(); } TryOpenAndExecuteWorkspace(extCommandData); // Disable the Dynamo button to prevent a re-run DynamoRevitApp.DynamoButtonEnabled = false; } catch (Exception ex) { // notify instrumentation InstrumentationLogger.LogException(ex); StabilityTracking.GetInstance().NotifyCrash(); MessageBox.Show(ex.ToString()); DynamoRevitApp.DynamoButtonEnabled = true; return(Result.Failed); } return(Result.Succeeded); }
/// <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); }
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 { #if ENABLE_DYNAMO_SCHEDULER extCommandData = commandData; commandData.Application.Idling += OnRevitIdleOnce; #else IdlePromise.ExecuteOnIdleAsync( delegate { // create core data models revitDynamoModel = InitializeCoreModel(commandData); dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); // show the window InitializeCoreView().Show(); TryOpenWorkspaceInCommandData(commandData); SubscribeViewActivating(commandData); }); #endif // 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 = DynamoRevitViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = revitDynamoModel, VisualizationManager = vizManager, WatchHandler = new RevitWatchHandler(vizManager, revitDynamoModel.PreferenceSettings) }); revitDynamoModel.ShutdownStarted += (drm) => { var uiApplication = DocumentManager.Instance.CurrentUIApplication; uiApplication.Idling += DeleteKeeperElementOnce; }; return(viewModel); }
/// <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) }); 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); }
public Result ExecuteCommand(DynamoRevitCommandData commandData) { var startupTimer = Stopwatch.StartNew(); if (ModelState == RevitDynamoModelState.StartedUIless) { if (CheckJournalForKey(commandData, JournalKeys.ShowUiKey, true) || CheckJournalForKey(commandData, JournalKeys.ModelShutDownKey)) { //When we move from UIless to UI we prefer to start with a fresh revitDynamoModel //in order to benefit from a startup sequence similar to Dynamo Revit UI launch. //Also there might be other situations which demand a new revitDynamoModel. //In order to be able to address them we process ModelShutDownKey. //An example of this situation is when you have a revitDynamoModel already started and you switch //the document in Revit. Since revitDynamoModel is well connected to the previous document we need to //shut it down and start a new one in order to able to run a graph in the new document. revitDynamoModel.ShutDown(false); ModelState = RevitDynamoModelState.NotStarted; } else { TryOpenAndExecuteWorkspaceInCommandData(commandData); return(Result.Succeeded); } } if (ModelState == RevitDynamoModelState.StartedUI) { TryOpenAndExecuteWorkspaceInCommandData(commandData); return(Result.Succeeded); } HandleDebug(commandData); InitializeCore(commandData); //subscribe to the assembly load AppDomain.CurrentDomain.AssemblyLoad += AssemblyLoad; try { extCommandData = commandData; UpdateSystemPathForProcess(); // create core data models revitDynamoModel = InitializeCoreModel(extCommandData); revitDynamoModel.UpdateManager.RegisterExternalApplicationProcessId(Process.GetCurrentProcess().Id); revitDynamoModel.Logger.Log("SYSTEM", string.Format("Environment Path:{0}", Environment.GetEnvironmentVariable("PATH"))); // handle initialization steps after RevitDynamoModel is created. revitDynamoModel.HandlePostInitialization(); ModelState = RevitDynamoModelState.StartedUIless; // show the window if (CheckJournalForKey(extCommandData, JournalKeys.ShowUiKey, true)) { dynamoViewModel = InitializeCoreViewModel(revitDynamoModel); // Let the host (e.g. Revit) control the rendering mode var save = RenderOptions.ProcessRenderMode; InitializeCoreView().Show(); RenderOptions.ProcessRenderMode = save; revitDynamoModel.Logger.Log(Dynamo.Applications.Properties.Resources.WPFRenderMode + RenderOptions.ProcessRenderMode.ToString()); ModelState = RevitDynamoModelState.StartedUI; // Disable the Dynamo button to prevent a re-run DynamoRevitApp.DynamoButtonEnabled = false; } //foreach preloaded exception send a notification to the Dynamo Logger //these are messages we want the user to notice. preLoadExceptions.ForEach(x => revitDynamoModel.Logger.LogNotification (revitDynamoModel.GetType().ToString(), x.GetType().ToString(), DynamoApplications.Properties.Resources.MismatchedAssemblyVersionShortMessage, x.Message)); TryOpenAndExecuteWorkspaceInCommandData(extCommandData); //unsubscribe to the assembly load AppDomain.CurrentDomain.AssemblyLoad -= AssemblyLoad; Analytics.TrackStartupTime("DynamoRevit", startupTimer.Elapsed, ModelState.ToString()); } catch (Exception ex) { // notify instrumentation Analytics.TrackException(ex, true); MessageBox.Show(ex.ToString()); DynamoRevitApp.DynamoButtonEnabled = true; //If for some reason Dynamo has crashed while startup make sure the Dynamo Model is properly shutdown. if (revitDynamoModel != null) { revitDynamoModel.ShutDown(false); revitDynamoModel = null; } return(Result.Failed); } return(Result.Succeeded); }
protected override void StartDynamo(TestSessionConfiguration testConfig) { try { UpdateSystemPathForProcess(); // create the transaction manager object TransactionManager.SetupManager(new AutomaticTransactionStrategy()); // Note that there is another data member pathResolver in base class // SystemTestBase. That pathResolver will be used only in StartDynamo // of the base class, here a local instance of pathResolver is used. // var commandData = new DynamoRevitCommandData(RevitTestExecutive.CommandData); var userDataFolder = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData), "Dynamo", "Dynamo Revit"); var commonDataFolder = Path.Combine(Environment.GetFolderPath( Environment.SpecialFolder.CommonApplicationData), "Autodesk", "RVT " + commandData.Application.Application.VersionNumber, "Dynamo"); // Set Path Resolver's user data folder and common data folder with DynamoRevit runtime. var pathResolverParams = new TestPathResolverParams() { UserDataRootFolder = userDataFolder, CommonDataRootFolder = commonDataFolder }; RevitTestPathResolver revitTestPathResolver = new RevitTestPathResolver(pathResolverParams); revitTestPathResolver.InitializePreloadedLibraries(); // Get the preloaded DynamoRevit Custom Nodes, and Add them to Preload Libraries. var preloadedLibraries = new List <string>(); GetLibrariesToPreload(preloadedLibraries); if (preloadedLibraries.Any()) { foreach (var preloadedLibrary in preloadedLibraries) { if (Directory.Exists(preloadedLibrary)) { revitTestPathResolver.AddNodeDirectory(preloadedLibrary); } else if (File.Exists(preloadedLibrary)) { revitTestPathResolver.AddPreloadLibraryPath(preloadedLibrary); } } } // Init DynamoTestPath to get DynamoSettings.xml which under user data folder PreferenceSettings.DynamoTestPath = string.Empty; //preload ASM and instruct dynamo to load that version of libG. var requestedLibGVersion = DynamoRevit.PreloadAsmFromRevit(); DynamoRevit.RevitDynamoModel = RevitDynamoModel.Start( new RevitDynamoModel.RevitStartConfiguration() { StartInTestMode = true, GeometryFactoryPath = DynamoRevit.GetGeometryFactoryPath(testConfig.DynamoCorePath, requestedLibGVersion), DynamoCorePath = testConfig.DynamoCorePath, PathResolver = revitTestPathResolver, Context = DynamoRevit.GetRevitContext(commandData), SchedulerThread = new TestSchedulerThread(), PackageManagerAddress = "https://www.dynamopackages.com", ExternalCommandData = commandData, ProcessMode = RevitTaskProcessMode }); Model = DynamoRevit.RevitDynamoModel; this.ViewModel = DynamoRevitViewModel.Start( new DynamoViewModel.StartConfiguration() { DynamoModel = DynamoRevit.RevitDynamoModel, }); var vm3D = ViewModel.Watch3DViewModels.FirstOrDefault(vm => vm is RevitWatch3DViewModel); if (vm3D != null) { vm3D.Active = false; } // Because the test framework does not work in the idle thread. // We need to trick Dynamo into believing that it's in the idle // thread already. IdlePromise.InIdleThread = true; } catch (Exception ex) { Console.WriteLine(ex.StackTrace); } }