示例#1
0
 private void DynamoRevitTestResultsView_OnClosed(object sender, EventArgs e)
 {
     IdlePromise.ExecuteOnIdle(delegate
     {
         DynamoLogger.Instance.FinishLogging();
     });
 }
示例#2
0
        private void Draw(IEnumerable <GeometryObject> geoms)
        {
            if (method == null)
            {
                method = GetTransientDisplayMethod();

                if (method == null)
                {
                    return;
                }
            }

            IdlePromise.ExecuteOnIdleAsync(
                () =>
            {
                TransactionManager.Instance.EnsureInTransaction(
                    DocumentManager.Instance.CurrentDBDocument);

                if (keeperId != ElementId.InvalidElementId &&
                    DocumentManager.Instance.CurrentDBDocument.GetElement(keeperId) != null)
                {
                    DocumentManager.Instance.CurrentUIDocument.Document.Delete(keeperId);
                    keeperId = ElementId.InvalidElementId;
                }

                var argsM = new object[4];
                argsM[0]  = DocumentManager.Instance.CurrentUIDocument.Document;
                argsM[1]  = ElementId.InvalidElementId;
                argsM[2]  = geoms;
                argsM[3]  = ElementId.InvalidElementId;
                keeperId  = (ElementId)method.Invoke(null, argsM);

                TransactionManager.Instance.ForceCloseTransaction();
            });
        }
示例#3
0
        public override void PostTraceReconciliation(Dictionary <Guid, List <ISerializable> > orphanedSerializables)
        {
            var orphanedIds =
                orphanedSerializables
                .SelectMany(kvp => kvp.Value)
                .Cast <SerializableId>()
                .Select(sid => sid.IntID).ToList();

            if (!orphanedIds.Any())
            {
                return;
            }

            if (IsTestMode)
            {
                DeleteOrphanedElements(orphanedIds, Logger);
            }
            else
            {
                // Delete all the orphans.
                IdlePromise.ExecuteOnIdleAsync(
                    () =>
                {
                    DeleteOrphanedElements(orphanedIds, Logger);
                });
            }
        }
示例#4
0
        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);
        }
示例#5
0
        /// <summary>
        /// Trigger a document regeneration in the idle context or without
        /// depending on the state of the transaction manager.
        /// </summary>
        public static void Regenerate()
        {
            if (TransactionManager.Instance.DoAssertInIdleThread)
            {
#if ENABLE_DYNAMO_SCHEDULER
                TransactionManager.Instance.EnsureInTransaction(
                    DocumentManager.Instance.CurrentDBDocument);
                Instance.CurrentDBDocument.Regenerate();
                // To ensure the transaction is closed in the idle process
                // so that the element is updated after this.
                TransactionManager.Instance.ForceCloseTransaction();
#else
                IdlePromise.ExecuteOnIdleSync(() =>
                {
                    TransactionManager.Instance.EnsureInTransaction(
                        DocumentManager.Instance.CurrentDBDocument);
                    Instance.CurrentDBDocument.Regenerate();
                    //To ensure the transaction is closed in the idle process
                    //so that the element is updated after this.
                    TransactionManager.Instance.ForceCloseTransaction();
                }
                                              );
#endif
            }
            else
            {
                Instance.CurrentDBDocument.Regenerate();
            }
        }
示例#6
0
 public override void ResetEngine(bool markNodesAsDirty = false)
 {
     IdlePromise.ExecuteOnIdleAsync(ResetEngineInternal);
     if (markNodesAsDirty)
     {
         Nodes.ForEach(n => n.RequiresRecalc = true);
     }
 }
示例#7
0
        protected override void PostShutdownCore(bool shutdownHost)
        {
#if !ENABLE_DYNAMO_SCHEDULER
            IdlePromise.ClearPromises();
            IdlePromise.Shutdown();
#endif
            base.PostShutdownCore(shutdownHost);
        }
示例#8
0
        private static void InitializeMaterials()
        {
            // Ensure that the current document has the needed materials
            // and graphic styles to support visualization in Revit.
            var mgr = MaterialsManager.Instance;

            IdlePromise.ExecuteOnIdleAsync(mgr.InitializeForActiveDocumentOnIdle);
        }
示例#9
0
        protected override void PreShutdownCore(bool shutdownHost)
        {
            if (shutdownHost)
            {
                IdlePromise.ExecuteOnShutdown(ShutdownRevitHost);
            }

            base.PreShutdownCore(shutdownHost);
        }
示例#10
0
 /// <summary>
 /// Executes right before Dynamo closes, gives you the chance to cache whatever you might want.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void dynamoView_Closing(object sender, EventArgs e)
 {
     // cache the size of the window for later reloading
     dynamoViewX      = dynamoView.Left;
     dynamoViewY      = dynamoView.Top;
     dynamoViewWidth  = dynamoView.ActualWidth;
     dynamoViewHeight = dynamoView.ActualHeight;
     IdlePromise.ClearPromises();
 }
示例#11
0
 private void selectButton_Click(object sender, RoutedEventArgs e)
 {
     _selectButton.IsEnabled = false;
     IdlePromise.ExecuteOnIdle(
         delegate
     {
         OnSelectClick();
         _selectButton.IsEnabled = true;
     });
 }
示例#12
0
        private void DrawToAlternateContext(List <GeometryObject> geoms)
        {
            Type geometryElementType = typeof(GeometryElement);

            MethodInfo[] geometryElementTypeMethods = geometryElementType.GetMethods(BindingFlags.Static | BindingFlags.Public);

            var method =
                geometryElementTypeMethods.FirstOrDefault(x => x.Name == "SetForTransientDisplay");

            if (method == null)
            {
                return;
            }

            var styles = new FilteredElementCollector(dynRevitSettings.Doc.Document);

            styles.OfClass(typeof(GraphicsStyle));

            var gStyle = styles.ToElements().FirstOrDefault(x => x.Name == "Dynamo");

            IdlePromise.ExecuteOnIdle(
                () =>
            {
                dynRevitSettings.Controller.InitTransaction();

                if (_keeperId != ElementId.InvalidElementId)
                {
                    dynRevitSettings.Doc.Document.Delete(_keeperId);
                    _keeperId = ElementId.InvalidElementId;
                }

                var argsM = new object[4];
                argsM[0]  = dynRevitSettings.Doc.Document;
                argsM[1]  = ElementId.InvalidElementId;
                argsM[2]  = geoms;
                if (gStyle != null)
                {
                    argsM[3] = gStyle.Id;
                }
                else
                {
                    argsM[3] = ElementId.InvalidElementId;
                }

                _keeperId = (ElementId)method.Invoke(null, argsM);

                //keeperId = GeometryElement.SetForTransientDisplay(dynRevitSettings.Doc.Document, ElementId.InvalidElementId, geoms,
                //                                       ElementId.InvalidElementId);

                dynRevitSettings.Controller.EndTransaction();
            });
        }
示例#13
0
        protected override void Run(List <NodeModel> topElements, FScheme.Expression runningExpression)
        {
            var model = (DynamoRevitViewModel)DynamoViewModel;

            //If we are not running in debug...
            if (!DynamoViewModel.RunInDebug)
            {
                //Do we need manual transaction control?
                bool manualTrans = topElements.Any(CheckManualTransaction.TraverseUntilAny);

                //Can we avoid running everything in the Revit Idle thread?
                bool noIdleThread = manualTrans ||
                                    !topElements.Any(CheckRequiresTransaction.TraverseUntilAny);

                //If we don't need to be in the idle thread...
                if (noIdleThread || IsTestMode)
                {
                    //DynamoLogger.Instance.Log("Running expression in evaluation thread...");
                    TransMode = TransactionMode.Manual; //Manual transaction control

                    if (IsTestMode)
                    {
                        TransMode = TransactionMode.Automatic;
                    }

                    InIdleThread = false;                     //Not in idle thread at the moment
                    base.Run(topElements, runningExpression); //Just run the Run Delegate
                }
                else //otherwise...
                {
                    //DynamoLogger.Instance.Log("Running expression in Revit's Idle thread...");
                    TransMode = TransactionMode.Automatic; //Automatic transaction control

                    Debug.WriteLine("Adding a run to the idle stack.");
                    InIdleThread = true; //Now in the idle thread.
                    IdlePromise.ExecuteOnIdle(
                        () => base.Run(topElements, runningExpression),
                        false); //Execute the Run Delegate in the Idle thread.
                }
            }
            else //If we are in debug mode...
            {
                TransMode    = TransactionMode.Debug; //Debug transaction control
                InIdleThread = true; //Everything will be evaluated in the idle thread.

                DynamoLogger.Instance.Log("Running expression in debug.");

                //Execute the Run Delegate.
                base.Run(topElements, runningExpression);
            }
        }
示例#14
0
        protected override void Run(IEnumerable <dynNodeModel> topElements, FScheme.Expression runningExpression)
        {
            //If we are not running in debug...
            if (!this.DynamoViewModel.RunInDebug)
            {
                //Do we need manual transaction control?
                bool manualTrans = topElements.Any((DynamoViewModel as DynamoRevitViewModel).CheckManualTransaction.TraverseUntilAny);

                //Can we avoid running everything in the Revit Idle thread?
                bool noIdleThread = manualTrans ||
                                    !topElements.Any((DynamoViewModel as DynamoRevitViewModel).CheckRequiresTransaction.TraverseUntilAny);

                //If we don't need to be in the idle thread...
                if (noIdleThread || this.Testing)
                {
                    DynamoLogger.Instance.Log("Running expression in evaluation thread...");
                    (DynamoViewModel as DynamoRevitViewModel).TransMode = DynamoRevitViewModel.TransactionMode.Manual; //Manual transaction control

                    if (this.Testing)
                    {
                        (DynamoViewModel as DynamoRevitViewModel).TransMode = DynamoRevitViewModel.TransactionMode.Automatic;
                    }

                    this.InIdleThread = false;                //Not in idle thread at the moment
                    base.Run(topElements, runningExpression); //Just run the Run Delegate
                }
                else //otherwise...
                {
                    DynamoLogger.Instance.Log("Running expression in Revit's Idle thread...");
                    (DynamoViewModel as DynamoRevitViewModel).TransMode = DynamoRevitViewModel.TransactionMode.Automatic; //Automatic transaction control

                    Debug.WriteLine("Adding a run to the idle stack.");
                    this.InIdleThread = true; //Now in the idle thread.
                    IdlePromise.ExecuteOnIdle(new Action(
                                                  () => base.Run(topElements, runningExpression)),
                                              false); //Execute the Run Delegate in the Idle thread.
                }
            }
            else //If we are in debug mode...
            {
                (DynamoViewModel as DynamoRevitViewModel).TransMode = DynamoRevitViewModel.TransactionMode.Debug; //Debug transaction control
                this.InIdleThread = true; //Everything will be evaluated in the idle thread.

                dynSettings.Controller.DynamoViewModel.Log("Running expression in debug.");

                //Execute the Run Delegate.
                base.Run(topElements, runningExpression);
            }
        }
示例#15
0
        private static void InitializeCore(ExternalCommandData commandData)
        {
            if (initializedCore)
            {
                return;
            }

            IdlePromise.RegisterIdle(commandData.Application);
            InitializeAssemblies();
            InitializeUnits();
            InitializeDocumentManager(commandData);
            InitializeMigrationManager();

            initializedCore = true;
        }
示例#16
0
        /// <summary>
        /// Destroy all elements belonging to this dynElement
        /// </summary>
        public override void Destroy()
        {
            var controller = dynRevitSettings.Controller;

            IdlePromise.ExecuteOnIdle(
                delegate
            {
                controller.InitTransaction();
                try
                {
                    runCount = 0;

                    var query = controller.DynamoViewModel.Model.HomeSpace.Nodes
                                .Where(x => x is dynFunctionWithRevit)
                                .Select(x => (x as dynFunctionWithRevit).ElementsContainer)
                                .Where(c => c.HasElements(GUID))
                                .SelectMany(c => c[GUID]);

                    foreach (var els in query)
                    {
                        foreach (ElementId e in els)
                        {
                            try
                            {
                                dynRevitSettings.Doc.Document.Delete(e);
                            }
                            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                            {
                                //TODO: Flesh out?
                            }
                        }
                        els.Clear();
                    }
                }
                catch (Exception ex)
                {
                    dynSettings.Controller.DynamoViewModel.Log(
                        "Error deleting elements: "
                        + ex.GetType().Name
                        + " -- " + ex.Message
                        );
                }
                controller.EndTransaction();
                WorkSpace.Modified();
            },
                true
                );
        }
示例#17
0
        void CleanupVisualizations(object sender, EventArgs e)
        {
            IdlePromise.ExecuteOnIdle(
                () =>
            {
                dynRevitSettings.Controller.InitTransaction();

                if (_keeperId != ElementId.InvalidElementId)
                {
                    dynRevitSettings.Doc.Document.Delete(_keeperId);
                    _keeperId = ElementId.InvalidElementId;
                }

                dynRevitSettings.Controller.EndTransaction();
            });
        }
        /// <summary>
        /// Destroy all elements belonging to this dynElement
        /// </summary>
        public override void Destroy()
        {
            var controller = dynRevitSettings.Controller;

            IdlePromise.ExecuteOnIdle(
                delegate
            {
                controller.InitTransaction();
                try
                {
                    _runCount = 0;

                    //TODO: Re-enable once similar functionality is fleshed out for dynFunctionWithRevit
                    //var query = controller.DynamoViewModel.Model.HomeSpace.Nodes
                    //    .OfType<dynFunctionWithRevit>()
                    //    .Select(x => x.ElementsContainer)
                    //    .Where(c => c.HasElements(GUID))
                    //    .SelectMany(c => c[GUID]);

                    foreach (var els in elements)
                    {
                        foreach (ElementId e in els)
                        {
                            try
                            {
                                dynRevitSettings.Doc.Document.Delete(e);
                            }
                            catch (Autodesk.Revit.Exceptions.InvalidOperationException)
                            {
                                //TODO: Flesh out?
                            }
                        }
                        els.Clear();
                    }
                }
                catch (Exception ex)
                {
                    DynamoLogger.Instance.Log(
                        "Error deleting elements: "
                        + ex.GetType().Name
                        + " -- " + ex.Message
                        );
                }
                controller.EndTransaction();
                WorkSpace.Modified();
            });
        }
示例#19
0
 /// <summary>
 /// Trigger a document regeneration in the idle context or without
 /// depending on the state of the transaction manager.
 /// </summary>
 public static void Regenerate()
 {
     if (TransactionManager.Instance.DoAssertInIdleThread)
     {
         IdlePromise.ExecuteOnIdleSync(() =>
         {
             TransactionManager.Instance.EnsureInTransaction(
                 DocumentManager.Instance.CurrentDBDocument);
             Instance.CurrentDBDocument.Regenerate();
         }
                                       );
     }
     else
     {
         Instance.CurrentDBDocument.Regenerate();
     }
 }
示例#20
0
        protected override void OnClear()
        {
            IdlePromise.ExecuteOnIdleAsync(
                () =>
            {
                TransactionManager.Instance.EnsureInTransaction(
                    DocumentManager.Instance.CurrentDBDocument);

                if (keeperId != ElementId.InvalidElementId)
                {
                    DocumentManager.Instance.CurrentUIDocument.Document.Delete(keeperId);
                    keeperId = ElementId.InvalidElementId;
                }

                TransactionManager.Instance.ForceCloseTransaction();
            });
        }
示例#21
0
        //private void DrawContainers(Value val, string id)
        //{
        //    if (val.IsList)
        //    {
        //        foreach (Value v in ((Value.List)val).Item)
        //        {
        //            DrawContainers(v, id);
        //        }
        //    }
        //    if (val.IsContainer)
        //    {
        //        var drawable = ((Value.Container)val).Item;

        //        //support drawing XYZs geometry objects or LibG graphic items
        //        if(drawable is XYZ || drawable is GeometryObject || drawable is GraphicItem )
        //        {
        //            VisualizationManager.Visualizations[id].Geometry.Add(drawable);
        //        }
        //    }
        //}

        Value newEval(bool dirty, string script, dynamic bindings, dynamic inputs)
        {
            bool transactionRunning = Transaction != null && Transaction.GetStatus() == TransactionStatus.Started;

            Value result = null;

            if (dynRevitSettings.Controller.InIdleThread)
            {
                result = _oldPyEval(dirty, script, bindings, inputs);
            }
            else
            {
                result = IdlePromise <Value> .ExecuteOnIdle(
                    () => _oldPyEval(dirty, script, bindings, inputs));
            }

            if (transactionRunning)
            {
                if (!IsTransactionActive())
                {
                    InitTransaction();
                }
                else
                {
                    var ts = Transaction.GetStatus();
                    if (ts != TransactionStatus.Started)
                    {
                        if (ts != TransactionStatus.RolledBack)
                        {
                            CancelTransaction();
                        }
                        InitTransaction();
                    }
                }
            }
            else if (DynamoViewModel.RunInDebug)
            {
                if (IsTransactionActive())
                {
                    EndTransaction();
                }
            }

            return(result);
        }
示例#22
0
        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);
        }
示例#23
0
        public override void ShutDown()
        {
            IdlePromise.ExecuteOnShutdown(
                delegate
            {
                var transaction = new Autodesk.Revit.DB.Transaction(dynRevitSettings.Doc.Document, "Dynamo Script");
                transaction.Start();

                if (_keeperId != ElementId.InvalidElementId)
                {
                    dynRevitSettings.Doc.Document.Delete(_keeperId);
                    _keeperId = ElementId.InvalidElementId;
                }

                transaction.Commit();
            });

            base.ShutDown();
            Updater.UnRegisterAllChangeHooks();
            RevertPythonBindings();
        }
示例#24
0
 public override void Destroy()
 {
     IdlePromise.ExecuteOnIdle(
         delegate
     {
         dynRevitSettings.Controller.InitTransaction();
         try
         {
             ElementsContainer.DestroyAll();
         }
         catch (Exception ex)
         {
             DynamoLogger.Instance.Log(
                 "Error deleting elements: "
                 + ex.GetType().Name
                 + " -- " + ex.Message);
         }
         dynRevitSettings.Controller.EndTransaction();
         WorkSpace.Modified();
     });
 }
示例#25
0
        protected override void OnEvaluationCompleted(object sender, EventArgs e)
        {
            base.OnEvaluationCompleted(sender, e);

            //Cleanup Delegate
            Action cleanup = delegate
            {
                //TODO: perhaps this should occur inside of ResetRuns in the event that
                //      there is nothing to be deleted?
                InitTransaction(); //Initialize a transaction (if one hasn't been aleady)

                //Reset all elements
                var query = dynSettings.Controller.DynamoModel.AllNodes
                            .OfType <RevitTransactionNode>();

                foreach (RevitTransactionNode element in query)
                {
                    element.ResetRuns();
                }

                //////
                /* FOR NON-DEBUG RUNS, THIS IS THE ACTUAL END POINT FOR DYNAMO TRANSACTION */
                //////

                EndTransaction(); //Close global transaction.
            };

            //If we're in a debug run or not already in the idle thread, then run the Cleanup Delegate
            //from the idle thread. Otherwise, just run it in this thread.
            if (dynSettings.Controller.DynamoViewModel.RunInDebug || !InIdleThread && !Testing)
            {
                IdlePromise.ExecuteOnIdle(cleanup, false);
            }
            else
            {
                cleanup();
            }
        }
示例#26
0
        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);
        }
示例#27
0
        public override void ShutDown(bool shutDownHost)
        {
            IdlePromise.ExecuteOnShutdown(
                delegate
            {
                var transaction = new Autodesk.Revit.DB.Transaction(dynRevitSettings.Doc.Document, "Dynamo Script");
                transaction.Start();

                if (_keeperId != ElementId.InvalidElementId)
                {
                    dynRevitSettings.Doc.Document.Delete(_keeperId);
                    _keeperId = ElementId.InvalidElementId;
                }

                transaction.Commit();
            });

            base.ShutDown(shutDownHost);
            Updater.UnRegisterAllChangeHooks();
            RevertPythonBindings();

            if (shutDownHost)
            {
                //shut down revit
                var exitCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit);
                var uiapp       = dynRevitSettings.Revit.ActiveUIDocument.Application;
                if (uiapp.CanPostCommand(exitCommand))
                {
                    uiapp.PostCommand(exitCommand);
                }
                else
                {
                    MessageBox.Show(
                        "A command in progress prevented Dynamo from closing revit. Dynamo update will be cancelled.");
                }
            }
        }
示例#28
0
        protected override void OnEvaluationCompleted()
        {
            base.OnEvaluationCompleted();

            //Cleanup Delegate
            Action cleanup = delegate
            {
                this.InitTransaction(); //Initialize a transaction (if one hasn't been aleady)

                //Reset all elements
                foreach (var element in dynSettings.Controller.DynamoViewModel.AllNodes)
                {
                    if (element is dynRevitTransactionNode)
                    {
                        (element as dynRevitTransactionNode).ResetRuns();
                    }
                }

                //////
                /* FOR NON-DEBUG RUNS, THIS IS THE ACTUAL END POINT FOR DYNAMO TRANSACTION */
                //////

                this.EndTransaction(); //Close global transaction.
            };

            //If we're in a debug run or not already in the idle thread, then run the Cleanup Delegate
            //from the idle thread. Otherwise, just run it in this thread.
            if (dynSettings.Controller.DynamoViewModel.RunInDebug || !InIdleThread && !this.Testing)
            {
                IdlePromise.ExecuteOnIdle(cleanup, false);
            }
            else
            {
                cleanup();
            }
        }
示例#29
0
        public override void ShutDown(bool shutDownHost)
        {
            DisposeLogic.IsShuttingDown = true;

            OnShuttingDown();

            base.ShutDown(shutDownHost);

            // unsubscribe events
            RevitServicesUpdater.UnRegisterAllChangeHooks();

            UnsubscribeDocumentManagerEvents();
            UnsubscribeRevitServicesUpdaterEvents();
            UnsubscribeTransactionManagerEvents();

            if (shutDownHost)
            {
                // this method cannot be called without Revit 2014
                var           exitCommand = RevitCommandId.LookupPostableCommandId(PostableCommand.ExitRevit);
                UIApplication uiapp       = DocumentManager.Instance.CurrentUIApplication;

                IdlePromise.ExecuteOnIdleAsync(
                    () =>
                {
                    if (uiapp.CanPostCommand(exitCommand))
                    {
                        uiapp.PostCommand(exitCommand);
                    }
                    else
                    {
                        MessageBox.Show(
                            "A command in progress prevented Dynamo from closing revit. Dynamo update will be cancelled.");
                    }
                });
            }
        }
示例#30
0
        public Result OnStartup(UIControlledApplication application)
        {
            try
            {
                //TAF load english_us TODO add a way to localize
                res = Resource_en_us.ResourceManager;
                // Create new ribbon panel
                RibbonPanel ribbonPanel = application.CreateRibbonPanel(res.GetString("App_Description"));

                //Create a push button in the ribbon panel
                var pushButton = ribbonPanel.AddItem(new PushButtonData("Dynamo",
                                                                        res.GetString("App_Name"), m_AssemblyName,
                                                                        "Dynamo.Applications.DynamoRevit")) as
                                 PushButton;

                Bitmap dynamoIcon = Resources.logo_square_32x32;


                BitmapSource bitmapSource = Imaging.CreateBitmapSourceFromHBitmap(
                    dynamoIcon.GetHbitmap(),
                    IntPtr.Zero,
                    Int32Rect.Empty,
                    BitmapSizeOptions.FromEmptyOptions());

                pushButton.LargeImage = bitmapSource;
                pushButton.Image      = bitmapSource;

                IdlePromise.RegisterIdle(application);

                Updater = new DynamoUpdater(application.ActiveAddInId, application.ControlledApplication);
                if (!UpdaterRegistry.IsUpdaterRegistered(Updater.GetUpdaterId()))
                {
                    UpdaterRegistry.RegisterUpdater(Updater);
                }

                var SpatialFieldFilter           = new ElementClassFilter(typeof(SpatialFieldManager));
                var familyFilter                 = new ElementClassFilter(typeof(FamilyInstance));
                var refPointFilter               = new ElementCategoryFilter(BuiltInCategory.OST_ReferencePoints);
                var modelCurveFilter             = new ElementClassFilter(typeof(CurveElement));
                var sunFilter                    = new ElementClassFilter(typeof(SunAndShadowSettings));
                IList <ElementFilter> filterList = new List <ElementFilter>();

                filterList.Add(SpatialFieldFilter);
                filterList.Add(familyFilter);
                filterList.Add(modelCurveFilter);
                filterList.Add(refPointFilter);
                filterList.Add(sunFilter);

                ElementFilter filter = new LogicalOrFilter(filterList);

                UpdaterRegistry.AddTrigger(Updater.GetUpdaterId(), filter, Element.GetChangeTypeAny());
                UpdaterRegistry.AddTrigger(Updater.GetUpdaterId(), filter, Element.GetChangeTypeElementDeletion());
                UpdaterRegistry.AddTrigger(Updater.GetUpdaterId(), filter, Element.GetChangeTypeElementAddition());

                env = new ExecutionEnvironment();

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
                return(Result.Failed);
            }
        }