Example #1
0
            // Execution method for the updater
            public void Execute(UpdaterData data)
            {
                // Remove old idling event callback
                UIApplication uiApp = new UIApplication(data.GetDocument().Application);

                uiApp.Idling -= containerOld.UpdateWhileIdling;
                containerOld.Stop();

                // Clear the current AVF results
                Document            doc        = data.GetDocument();
                View                activeView = doc.GetElement(s_activeViewId) as View;
                SpatialFieldManager sfm        = SpatialFieldManager.GetSpatialFieldManager(activeView);

                sfm.Clear();

                // Restart the multithread calculation with a new container
                Element modifiedElem = doc.GetElement(data.GetModifiedElementIds().First <ElementId>());
                MultithreadedCalculationContainer container = MultithreadedCalculation.CreateContainer(modifiedElem);

                containerOld = container;

                // Setup the new idling callback
                uiApp.Idling += new EventHandler <IdlingEventArgs>(container.UpdateWhileIdling);

                // Start the thread
                Thread threadNew = new Thread(new ThreadStart(container.Run));

                threadNew.Start();
            }
Example #2
0
            // Execution method for the updater
            public void Execute(UpdaterData data)
            {
                // Remove old idling event callback
                UIApplication uiApp = new UIApplication(data.GetDocument().Application);
                uiApp.Idling -= containerOld.UpdateWhileIdling;
                containerOld.Stop();

                // Clear the current AVF results
                Document doc = data.GetDocument();
                View activeView = doc.get_Element(s_activeViewId) as View;
                SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(activeView);
                sfm.Clear();

                // Restart the multithread calculation with a new container
                Element modifiedElem = doc.get_Element(data.GetModifiedElementIds().First<ElementId>());
                MultithreadedCalculationContainer container = MultithreadedCalculation.CreateContainer(modifiedElem);
                containerOld = container;

                // Setup the new idling callback
                uiApp.Idling += new EventHandler<IdlingEventArgs>(container.UpdateWhileIdling);

                // Start the thread
                Thread threadNew = new Thread(new ThreadStart(container.Run));
                threadNew.Start();
            }
Example #3
0
 public SpatialFieldUpdater(MultithreadedCalculationContainer _container, AddInId addinId)
 {
     containerOld = _container;
     s_updaterId = new UpdaterId(addinId, new Guid("FBF2F6B2-4C06-42d4-97C1-D1B4EB593EFF"));
 }
Example #4
0
        public Autodesk.Revit.UI.Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
        {
            UIApplication uiApp = commandData.Application;
            UIDocument    uiDoc = uiApp.ActiveUIDocument;
            Document      doc   = uiDoc.Document;

            s_docName = doc.PathName;

            Element element = null;

            try
            {
                element = doc.GetElement(uiDoc.Selection.PickObject(ObjectType.Element, "Select an element for the AVF demonstration."));
            }
            catch (System.Exception)
            {
                message = "User aborted the tool.";
                return(Result.Cancelled);
            }

            // Set up SpatialFieldManager to hold results
            s_activeViewId = doc.ActiveView.Id;
            SpatialFieldManager oldSfm = null;
            View oldView = null;

            if (s_oldViewId != null)
            {
                oldView = doc.GetElement(s_oldViewId) as View;
            }
            if (oldView != null)
            {
                oldSfm = SpatialFieldManager.GetSpatialFieldManager(oldView);
            }
            // If a previous SFM was being managed, delete it
            if (oldSfm != null)
            {
                oldSfm.RemoveSpatialFieldPrimitive(s_oldSpatialFieldId);
            }

            // Setup container object for executing the calculation
            MultithreadedCalculationContainer container = CreateContainer(element);

            // Register updater to watch for geometry changes
            SpatialFieldUpdater updater = new SpatialFieldUpdater(container, uiApp.ActiveAddInId);

            if (!UpdaterRegistry.IsUpdaterRegistered(updater.GetUpdaterId()))
            {
                UpdaterRegistry.RegisterUpdater(updater, doc);
            }
            IList <ElementId> idCollection = new List <ElementId>();

            idCollection.Add(element.Id);
            UpdaterRegistry.RemoveAllTriggers(s_updaterId);
            UpdaterRegistry.AddTrigger(updater.GetUpdaterId(), doc, idCollection, Element.GetChangeTypeGeometry());

            // Register idling event
            uiApp.Idling += new EventHandler <IdlingEventArgs>(container.UpdateWhileIdling);

            // Start new thread
            Thread thread = new Thread(new ThreadStart(container.Run));

            thread.Start();

            return(Autodesk.Revit.UI.Result.Succeeded);
        }
Example #5
0
 public SpatialFieldUpdater(MultithreadedCalculationContainer _container, AddInId addinId)
 {
     containerOld = _container;
     s_updaterId  = new UpdaterId(addinId, new Guid("FBF2F6B2-4C06-42d4-97C1-D1B4EB593EFF"));
 }