Пример #1
0
        public DynamoController_Revit(RevitServicesUpdater updater, string context, IUpdateManager updateManager, ILogger logger )
            : base(
                context,
                updateManager,
                logger,
                new RevitWatchHandler(),
                Dynamo.PreferenceSettings.Load())
        {
            Updater = updater;

            dynRevitSettings.Controller = this;

            DocumentManager.Instance.CurrentUIApplication.Application.DocumentClosed +=
                Application_DocumentClosed;
            DocumentManager.Instance.CurrentUIApplication.Application.DocumentOpened +=
                Application_DocumentOpened;
            DocumentManager.Instance.CurrentUIApplication.ViewActivated += Revit_ViewActivated;

            TransactionWrapper = TransactionManager.Instance.TransactionWrapper;
            TransactionWrapper.TransactionStarted += TransactionManager_TransactionCommitted;
            TransactionWrapper.TransactionCancelled += TransactionManager_TransactionCancelled;
            TransactionWrapper.FailuresRaised += TransactionManager_FailuresRaised;

            MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrationsRevit));
            ElementNameStore = new Dictionary<ElementId, string>();

            EngineController.ImportLibrary("RevitNodes.dll");
        }
Пример #2
0
        /// <summary>
        ///     Initializes the static Instance of the RevitServicesUpdater.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="updaters"></param>
        public static void Initialize(ControlledApplication app, IEnumerable <IUpdater> updaters)
        {
            lock (mutex)
            {
                if (instance != null)
                {
                    DisposeInstance();
                }

                instance = new RevitServicesUpdater(app, updaters);
            }
        }
Пример #3
0
        /// <summary>
        ///     Initializes the static Instance of the RevitServicesUpdater.
        /// </summary>
        /// <param name="app"></param>
        /// <param name="updaters"></param>
        public static void Initialize(IEnumerable <IUpdater> updaters)
        {
            lock (mutex)
            {
                if (instance != null)
                {
                    DisposeInstance();
                }

                instance = new RevitServicesUpdater(updaters);
            }
        }
Пример #4
0
 /// <summary>
 ///     Initializes the static Instance of the RevitServicesUpdater.
 /// </summary>
 /// <param name="app"></param>
 /// <param name="updaters"></param>
 public static void Initialize(ControlledApplication app, IEnumerable <IUpdater> updaters)
 {
     lock (mutex)
     {
         if (instance == null)
         {
             instance = new RevitServicesUpdater(app, updaters);
         }
         else
         {
             throw new InvalidOperationException("RevitServicesUpdater can only be initialized once.");
         }
     }
 }
Пример #5
0
        private RevitDynamoModel(StartConfiguration configuration) :
            base(configuration)
        {
            string context = configuration.Context;
            IPreferences preferences = configuration.Preferences;
            string corePath = configuration.DynamoCorePath;
            bool isTestMode = configuration.StartInTestMode;

            RevitServicesUpdater = new RevitServicesUpdater(DynamoRevitApp.ControlledApplication, DynamoRevitApp.Updaters);
            SubscribeRevitServicesUpdaterEvents();

            InitializeDocumentManager();
            SubscribeDocumentManagerEvents();
            SubscribeTransactionManagerEvents();

            SetupPython();
        }
Пример #6
0
        public DynamoController_Revit(RevitServicesUpdater updater, Type viewModelType, string context)
            : base(viewModelType,
                context,
                new UpdateManager.UpdateManager(),
                new RevitWatchHandler(),
                Dynamo.PreferenceSettings.Load())
        {
            Updater = updater;

            dynRevitSettings.Controller = this;

            //Predicate<NodeModel> requiresTransactionPredicate = node => node is RevitTransactionNode;
            //CheckRequiresTransaction = new PredicateTraverser(requiresTransactionPredicate);

            //Predicate<NodeModel> manualTransactionPredicate = node => node is Transaction;
            //CheckManualTransaction = new PredicateTraverser(manualTransactionPredicate);

            dynSettings.Controller.DynamoViewModel.RequestAuthentication += RegisterSingleSignOn;

            AddPythonBindings();

            DocumentManager.Instance.CurrentUIApplication.Application.DocumentClosed +=
                Application_DocumentClosed;
            DocumentManager.Instance.CurrentUIApplication.Application.DocumentOpened +=
                Application_DocumentOpened;
            DocumentManager.Instance.CurrentUIApplication.ViewActivated += Revit_ViewActivated;

            //allow the showing of elements in context
            dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.CanFindNodesFromElements = true;
            dynSettings.Controller.DynamoViewModel.CurrentSpaceViewModel.FindNodesFromElements =
                FindNodesFromSelection;

            TransactionWrapper = TransactionManager.Instance.TransactionWrapper;
            TransactionWrapper.TransactionStarted += TransactionManager_TransactionCommitted;
            TransactionWrapper.TransactionCancelled += TransactionManager_TransactionCancelled;
            TransactionWrapper.FailuresRaised += TransactionManager_FailuresRaised;

            MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrationsRevit));
            ElementNameStore = new Dictionary<ElementId, string>();

            EngineController.ImportLibrary("RevitNodes.dll");
        }
Пример #7
0
        public static DynamoController_Revit CreateDynamoRevitControllerAndViewModel(
            RevitServicesUpdater updater, DynamoLogger logger, string context)
        {
            BaseUnit.HostApplicationInternalAreaUnit = DynamoAreaUnit.SquareFoot;
            BaseUnit.HostApplicationInternalLengthUnit = DynamoLengthUnit.DecimalFoot;
            BaseUnit.HostApplicationInternalVolumeUnit = DynamoVolumeUnit.CubicFoot;

            var updateManager = new UpdateManager.UpdateManager(logger);

            string corePath =
                Path.GetFullPath(
                    Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + @"\..\");
            var dynamoController = new DynamoController_Revit(
                updater,
                context,
                updateManager,
                corePath);

            // Generate a view model to be the data context for the view
            dynamoController.DynamoViewModel = new DynamoRevitViewModel(dynamoController, null);
            dynamoController.DynamoViewModel.RequestAuthentication +=
                dynamoController.RegisterSingleSignOn;
            dynamoController.DynamoViewModel.CurrentSpaceViewModel.CanFindNodesFromElements = true;
            dynamoController.DynamoViewModel.CurrentSpaceViewModel.FindNodesFromElements =
                dynamoController.FindNodesFromSelection;

            // Register the view model to handle sign-on requests
            dynSettings.Controller.DynamoViewModel.RequestAuthentication +=
                dynamoController.RegisterSingleSignOn;

            dynamoController.VisualizationManager = new VisualizationManagerRevit();

            return dynamoController;
        }
Пример #8
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            RevThread.IdlePromise.RegisterIdle(revit.Application);

            if (revit.JournalData != null && revit.JournalData.ContainsKey("debug"))
            {
                if (bool.Parse(revit.JournalData["debug"]))
                    Debugger.Launch();
            }

            AppDomain.CurrentDomain.AssemblyResolve +=
                Analyze.Render.AssemblyHelper.ResolveAssemblies;

            //Add an assembly load step for the System.Windows.Interactivity assembly
            //Revit owns a version of this as well. Adding our step here prevents a duplicative
            //load of the dll at a later time.
            string interactivityPath = Path.Combine(
                DynamoPathManager.Instance.MainExecPath,
                "System.Windows.Interactivity.dll");
            if (File.Exists(interactivityPath))
                Assembly.LoadFrom(interactivityPath);

            try
            {
                #region default level
                var fecLevel =
                    new FilteredElementCollector(revit.Application.ActiveUIDocument.Document);
                fecLevel.OfClass(typeof(Level));
                var defaultLevel = fecLevel.ToElements()[0] as Level;
                #endregion

                var logger = new DynamoLogger(DynamoPathManager.Instance.Logs);
                dynSettings.DynamoLogger = logger;

                if (DocumentManager.Instance.CurrentUIApplication == null)
                    DocumentManager.Instance.CurrentUIApplication = revit.Application;

                DocumentManager.OnLogError += dynSettings.DynamoLogger.Log;

                dynRevitSettings.DefaultLevel = defaultLevel;

                //TODO: has to be changed when we handle multiple docs
                Updater = new RevitServicesUpdater(
                    DynamoRevitApp.ControlledApplication,
                    DynamoRevitApp.Updaters);
                Updater.ElementAddedForID += ElementMappingCache.GetInstance().WatcherMethodForAdd;
                Updater.ElementsDeleted += ElementMappingCache.GetInstance().WatcherMethodForDelete;

                RevThread.IdlePromise.ExecuteOnIdleAsync(
                    delegate
                    {
                        //get window handle
                        IntPtr mwHandle = Process.GetCurrentProcess().MainWindowHandle;

                        var r = new Regex(@"\b(Autodesk |Structure |MEP |Architecture )\b");
                        string context = r.Replace(revit.Application.Application.VersionName, "");

                        //they changed the application version name conventions for vasari
                        //it no longer has a version year so we can't compare it to other versions
                        //TODO:come up with a more stable way to test for Vasari beta 3
                        if (context == "Vasari")
                            context = "Vasari 2014";

                        dynamoController = CreateDynamoRevitControllerAndViewModel(
                            Updater,
                            logger,
                            context);

                        var dynamoView = new DynamoView
                        {
                            DataContext = dynamoController.DynamoViewModel
                        };
                        dynamoController.UIDispatcher = dynamoView.Dispatcher;

                        //set window handle and show dynamo
                        new WindowInteropHelper(dynamoView).Owner = mwHandle;

                        handledCrash = false;

                        dynamoView.Show();

                        if (revit.JournalData != null && revit.JournalData.ContainsKey("dynPath"))
                            dynamoController.DynamoModel.OpenWorkspace(revit.JournalData["dynPath"]);

                        dynamoView.Dispatcher.UnhandledException += DispatcherOnUnhandledException;
                        dynamoView.Closing += dynamoView_Closing;
                        dynamoView.Closed += dynamoView_Closed;

                        revit.Application.ViewActivating += Application_ViewActivating;
                    });

                // Disable the Dynamo button to prevent a re-run
                DynamoRevitApp.DynamoButton.Enabled = false;
            }
            catch (Exception ex)
            {
                InstrumentationLogger.LogException(ex);
                StabilityTracking.GetInstance().NotifyCrash();

                //isRunning = false;
                MessageBox.Show(ex.ToString());

                dynSettings.DynamoLogger.LogError(ex.Message);
                dynSettings.DynamoLogger.LogError(ex.StackTrace);
                dynSettings.DynamoLogger.LogError("Dynamo log ended " + DateTime.Now);

                DynamoRevitApp.DynamoButton.Enabled = true;

                return Result.Failed;
            }

            return Result.Succeeded;
        }
Пример #9
0
        public DynamoController_Revit(RevitServicesUpdater updater, string context, IUpdateManager updateManager, string corePath)
            : base(
                context,
                updateManager,
                new RevitWatchHandler(),
                Dynamo.PreferenceSettings.Load(),
                corePath)
        {
            Updater = updater;

            dynRevitSettings.Controller = this;

            DocumentManager.Instance.CurrentUIApplication.Application.DocumentClosed +=
                Application_DocumentClosed;
            DocumentManager.Instance.CurrentUIApplication.Application.DocumentOpened +=
                Application_DocumentOpened;
            DocumentManager.Instance.CurrentUIApplication.ViewActivated += Revit_ViewActivated;

            // Set the intitial document.
            if (DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument != null)
            {
                DocumentManager.Instance.CurrentUIDocument =
                       DocumentManager.Instance.CurrentUIApplication.ActiveUIDocument;
                dynSettings.DynamoLogger.LogWarning(GetDocumentPointerMessage(), WarningLevel.Moderate);
            }

            TransactionWrapper = TransactionManager.Instance.TransactionWrapper;
            TransactionWrapper.TransactionStarted += TransactionManager_TransactionCommitted;
            TransactionWrapper.TransactionCancelled += TransactionManager_TransactionCancelled;
            TransactionWrapper.FailuresRaised += TransactionManager_FailuresRaised;

            MigrationManager.Instance.MigrationTargets.Add(typeof(WorkspaceMigrationsRevit));
            ElementNameStore = new Dictionary<ElementId, string>();

            SetupPython();

            Runner = new DynamoRunner_Revit(this);
        }
Пример #10
0
        private void StartDynamo()
        {
            try
            {
                var updater = new RevitServicesUpdater(DynamoRevitApp.ControlledApplication, DynamoRevitApp.Updaters);
                updater.ElementAddedForID += ElementMappingCache.GetInstance().WatcherMethodForAdd;
                updater.ElementsDeleted += ElementMappingCache.GetInstance().WatcherMethodForDelete;

                SIUnit.HostApplicationInternalAreaUnit = DynamoAreaUnit.SquareFoot;
                SIUnit.HostApplicationInternalLengthUnit = DynamoLengthUnit.DecimalFoot;
                SIUnit.HostApplicationInternalVolumeUnit = DynamoVolumeUnit.CubicFoot;

                var logger = new DynamoLogger(DynamoPathManager.Instance.Logs);
                dynSettings.DynamoLogger = logger;
                var updateManager = new UpdateManager.UpdateManager(logger);

                Controller = DynamoRevit.CreateDynamoRevitControllerAndViewModel(updater, logger, Context.NONE);
                DynamoController.IsTestMode = true;

                // create the transaction manager object
                TransactionManager.SetupManager(new AutomaticTransactionStrategy());

                // 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);
            }
        }
Пример #11
0
        public Result Execute(ExternalCommandData revit, ref string message, ElementSet elements)
        {
            AppDomain.CurrentDomain.AssemblyResolve += AssemblyHelper.CurrentDomain_AssemblyResolve;
            AppDomain.CurrentDomain.AssemblyResolve += DynamoRaaS.AssemblyHelper.ResolveAssemblies;

            //Add an assembly load step for the System.Windows.Interactivity assembly
            //Revit owns a version of this as well. Adding our step here prevents a duplicative
            //load of the dll at a later time.
            var assLoc = Assembly.GetExecutingAssembly().Location;
            var interactivityPath = Path.Combine(Path.GetDirectoryName(assLoc), "System.Windows.Interactivity.dll");
            var interactivityAss = Assembly.LoadFrom(interactivityPath);

            //When a user double-clicks the Dynamo icon, we need to make
            //sure that we don't create another instance of Dynamo.
            if (isRunning)
            {
                Debug.WriteLine("Dynamo is already running.");
                if (dynamoView != null)
                {
                    dynamoView.Focus();
                }
                return Result.Succeeded;
            }

            isRunning = true;

            try
            {
                #region default level

                var fecLevel = new FilteredElementCollector(revit.Application.ActiveUIDocument.Document);
                fecLevel.OfClass(typeof(Level));
                var defaultLevel = fecLevel.ToElements()[0] as Level;

                #endregion

                if (DocumentManager.Instance.CurrentUIApplication == null)
                    DocumentManager.Instance.CurrentUIApplication = revit.Application;

                DocumentManager.OnLogError += dynSettings.Controller.DynamoLogger.Log;

                dynRevitSettings.DefaultLevel = defaultLevel;

                //TODO: has to be changed when we handle multiple docs
                Updater = new RevitServicesUpdater(DynamoRevitApp.ControlledApplication, DynamoRevitApp.Updaters);
                Updater.ElementAddedForID += ElementMappingCache.GetInstance().WatcherMethodForAdd;
                Updater.ElementsDeleted += ElementMappingCache.GetInstance().WatcherMethodForDelete;

                RevThread.IdlePromise.ExecuteOnIdleAsync(
                    delegate
                    {
                        //get window handle
                        IntPtr mwHandle = Process.GetCurrentProcess().MainWindowHandle;

                        var r = new Regex(@"\b(Autodesk |Structure |MEP |Architecture )\b");
                        string context = r.Replace(revit.Application.Application.VersionName, "");

                        //they changed the application version name conventions for vasari
                        //it no longer has a version year so we can't compare it to other versions
                        //TODO:come up with a more stable way to test for Vasari beta 3
                        if (context == "Vasari")
                            context = "Vasari 2014";

                        BaseUnit.HostApplicationInternalAreaUnit = DynamoAreaUnit.SquareFoot;
                        BaseUnit.HostApplicationInternalLengthUnit = DynamoLengthUnit.DecimalFoot;
                        BaseUnit.HostApplicationInternalVolumeUnit = DynamoVolumeUnit.CubicFoot;

                        var logger = new DynamoLogger();
                        var updateManager = new UpdateManager.UpdateManager(logger);
                        dynamoController = new DynamoController_Revit(Updater, context, updateManager,logger);

                        // Generate a view model to be the data context for the view
                        dynamoController.DynamoViewModel = new DynamoRevitViewModel(dynamoController, null);
                        dynamoController.DynamoViewModel.RequestAuthentication += ((DynamoController_Revit)dynamoController).RegisterSingleSignOn;
                        dynamoController.DynamoViewModel.CurrentSpaceViewModel.CanFindNodesFromElements = true;
                        dynamoController.DynamoViewModel.CurrentSpaceViewModel.FindNodesFromElements = ((DynamoController_Revit)dynamoController).FindNodesFromSelection;
                        
                        // Register the view model to handle sign-on requests
                        dynSettings.Controller.DynamoViewModel.RequestAuthentication += ((DynamoController_Revit)dynamoController).RegisterSingleSignOn;

                        dynamoController.VisualizationManager = new VisualizationManagerRevit();
                        
                        dynamoView = new DynamoView { DataContext = dynamoController.DynamoViewModel };
                        dynamoController.UIDispatcher = dynamoView.Dispatcher;

                        //set window handle and show dynamo
                        new WindowInteropHelper(dynamoView).Owner = mwHandle;

                        handledCrash = false;

                        dynamoView.WindowStartupLocation = WindowStartupLocation.Manual;

                        Rectangle bounds = Screen.PrimaryScreen.Bounds;
                        dynamoView.Left = DynamoViewX ?? bounds.X;
                        dynamoView.Top = DynamoViewY ?? bounds.Y;
                        dynamoView.Width = DynamoViewWidth ?? 1000.0;
                        dynamoView.Height = DynamoViewHeight ?? 800.0;

                        dynamoView.Show();

                        dynamoView.Dispatcher.UnhandledException += DispatcherOnUnhandledException; 
                        dynamoView.Closing += dynamoView_Closing;
                        dynamoView.Closed += dynamoView_Closed;

                        revit.Application.ViewActivating += Application_ViewActivating;
                    });
            }
            catch (Exception ex)
            {
                isRunning = false;
                MessageBox.Show(ex.ToString());

                dynSettings.Controller.DynamoLogger.LogError(ex.Message);
                dynSettings.Controller.DynamoLogger.LogError(ex.StackTrace);
                dynSettings.Controller.DynamoLogger.LogError("Dynamo log ended " + DateTime.Now);

                return Result.Failed;
            }

            return Result.Succeeded;
        }