Esempio n. 1
0
        public Result Execute(
          ExternalCommandData commandData,
          ref string message,
          ElementSet elements)
        {
            #if !VERSION2014
            Debug.Print("Version 2013");
            #else
              Debug.Print( "Version 2014" );
            #endif // VERSION2014
            UIApplication uiapp = commandData.Application;
            UIDocument uidoc = uiapp.ActiveUIDocument;
            Application app = uiapp.Application;
            Document doc = uidoc.Document;

            // Create Analysis Results
            SpatialFieldManager sfm = SpatialFieldManager.GetSpatialFieldManager(doc.ActiveView);
            if (null == sfm)
            {
             sfm = SpatialFieldManager.CreateSpatialFieldManager(doc.ActiveView,1);
            }

            // Pick Space to perform analysis

            Reference reference = uidoc.Selection.PickObject(ObjectType.Element, new SpaceSelectionFilter(doc), "Select a Space");

            // Gather all spaceInfo
            RoomSpace roomSpace = new RoomSpace(doc, reference);

            // Perform calculations on selected space
            LightingCalculations lc = new LightingCalculations(doc,sfm);
            bool pbpcalc = lc.pointByPointCalculation(roomSpace);

            //Get Or Create Avs
            using (Transaction tx = new Transaction(doc))
            {
                tx.Start("DisplayResults");

                bool avs = lc.GetOrCreateAVS();

                tx.Commit();
            }

            return Result.Succeeded;
        }
        /// <summary>
        /// Gets the topmost face of the space geometry
        /// *Basically to use as a pseudo calc face to present
        /// the analysis results in the view
        /// </summary>
        /// <param name="space"></param>
        /// <returns>Topmost face of space geometry</returns>
        private Face GetFace(RoomSpace space)
        {
            Options options = new Options();
            options.ComputeReferences = true;

            GeometryElement ge = space.ParentSpaceObject.get_Geometry(options);
            //Array geoArray = ge.ToArray();
            //Solid sol = geoArray.GetValue(0) as Solid;
            Solid sol = ge.ElementAt(0) as Solid;
            Face face = sol.Faces.get_Item(1) as Face;

            return face;
        }
        // TODO: change to proper return value
        /// <summary>
        /// Method call to calculate light at points in space
        /// using Lumens property of light fixtures in space
        /// </summary>
        /// <param name="roomSpace"></param>
        /// <returns>TRUE always, need to fix to return more useful.</returns>
        public bool pointByPointCalculation(RoomSpace roomSpace)
        {
            // Perform PointByPoint lighting calc on RoomSpace

            // Get faces of roomSpace
            Face calcFace = GetFace(roomSpace);

            // bounding box UV
            BoundingBoxUV bb = calcFace.GetBoundingBox();
            UV min = bb.Min;
            UV max = bb.Max;

            // Face Transform
            UV faceCenter = new UV((max.U + min.U) / 2, (max.V + min.V) / 2);
            Transform computeDerivatives = calcFace.ComputeDerivatives(faceCenter);
            XYZ faceCenterNormal = computeDerivatives.BasisZ;

            // Normalize the normal vector and multiply by 2.5???
            XYZ faceCenterNormalMultiplied = faceCenterNormal.Normalize().Multiply(2.5);

            // Set Transform
            // Obsolete in 204:
            // Transform faceTransform = Transform.get_Translation(faceCenterNormalMultiplied);
            Transform faceTransform = Transform.CreateTranslation(faceCenterNormalMultiplied);

            List<double> doubleList = new List<double>();
            IList<UV> uvPts = new List<UV>();
            IList<ValueAtPoint> valList = new List<ValueAtPoint>();

            for (double u = min.U; u < max.U; u = u + (max.U - min.U) / 15)
            {
                for (double v = min.V; v < max.V; v = v + (max.V - min.V) / 15)
                {
                    UV uvPnt = new UV(u, v);
                    if (calcFace.IsInside(uvPnt))
                    {
                        XYZ pointToCalc = calcFace.Evaluate(uvPnt);
                        double resultFC = CalcFCAtPoint(pointToCalc, roomSpace.LightFixtures,roomSpace.CalcWorkPlane);
                        uvPts.Add(uvPnt);
                        doubleList.Add(resultFC);
                        valList.Add(new ValueAtPoint(doubleList));
                        doubleList.Clear();
                    }
                }
            }

            DoVisualization(uvPts, valList, calcFace, faceTransform);

            return true;
        }