예제 #1
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 = uiDoc.Selection.PickObject(ObjectType.Element, "Select an element for the AVF demonstration.").Element;
            }
            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.get_Element(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;
        }
예제 #2
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);
        }