Ejemplo n.º 1
0
        /// <summary>
        /// Initialise the external webcam event driver.
        /// </summary>
        public static void Start(View view, Reference r)
        {
            _faceReference = r;

            SpatialFieldManager sfm
                = SpatialFieldManager.GetSpatialFieldManager(
                      view);

            if (null == sfm)
            {
                sfm = SpatialFieldManager
                      .CreateSpatialFieldManager(view, 1);
            }
            else if (0 < _sfp_index)
            {
                sfm.RemoveSpatialFieldPrimitive(
                    _sfp_index);

                _sfp_index = -1;
            }

            _sfp_index = sfm.AddSpatialFieldPrimitive(
                _faceReference);

            _event = ExternalEvent.Create(
                new WebcamEventHandler());

            Thread thread = new Thread(
                new ThreadStart(Run));

            thread.Start();
        }
Ejemplo n.º 2
0
        public Result Execute(
            ExternalCommandData commandData,
            ref string message,
            ElementSet elements)
        {
            try
            {
                UIApplication uiapp = commandData.Application;
                UIDocument    uidoc = uiapp.ActiveUIDocument;
                Document      doc   = uidoc.Document;
                View          view  = doc.ActiveView; // maybe has to be 3D

                Reference r = uidoc.Selection.PickObject(
                    ObjectType.Face,
                    new BimElementFilter(),
                    _prompt);

                Debug.Assert(null != r,
                             "expected non-null reference from PickObject");

                Debug.Assert(null != r.Element,
                             "expected non-null element from PickObject");

                Debug.Assert(null != r.GeometryObject,
                             "expected non-null geometry object from PickObject");

                _faceReference = r;

                SpatialFieldManager sfm
                    = SpatialFieldManager.GetSpatialFieldManager(
                          view);

                if (null != sfm && 0 < _sfp_index)
                {
                    sfm.RemoveSpatialFieldPrimitive(
                        _sfp_index);

                    _sfp_index = -1;
                }

                SetAnalysisDisplayStyle(doc);

                uiapp.Idling
                    += new EventHandler <IdlingEventArgs>(
                           OnIdling);

                return(Result.Succeeded);
            }
            catch (Exception ex)
            {
                message = ex.Message;
                return(Result.Failed);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Set up the AVF spatial field manager
        /// for the given view.
        /// </summary>
        static void SetUpAvfSfm(
            View view,
            Reference faceReference)
        {
            if (view.AnalysisDisplayStyleId
                == ElementId.InvalidElementId)
            {
                SetAvfDisplayStyle(view);
            }

            _sfm = SpatialFieldManager
                   .GetSpatialFieldManager(view);

            if (null == _sfm)
            {
                _sfm = SpatialFieldManager
                       .CreateSpatialFieldManager(view, 1);
            }
            else if (0 < _sfp_index)
            {
                _sfm.RemoveSpatialFieldPrimitive(
                    _sfp_index);
            }

            _sfp_index = _sfm.AddSpatialFieldPrimitive(
                faceReference);

            if (-1 != _schemaId)
            {
                IList <int> results = _sfm.GetRegisteredResults();
                if (!results.Contains(_schemaId))
                {
                    _schemaId = -1;
                }
            }

            if (-1 == _schemaId)
            {
                AnalysisResultSchema schema
                    = new AnalysisResultSchema("Attenuation",
                                               "RvtFader signal attenuation");

                List <string> unitNames = new List <string>(new string[1] {
                    "dB"
                });
                List <double> unitFactors = new List <double>(new double[1] {
                    1.0
                });
                schema.SetUnits(unitNames, unitFactors);

                _schemaId = _sfm.RegisterResult(schema);
            }
        }
Ejemplo n.º 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);
        }