コード例 #1
0
        private double CalculateFAR(AreaProperties ap)
        {
            double far = 0;

            try
            {
                double sum = 0;

                foreach (int massId in ap.MassIDs)
                {
                    if (massDictionary.ContainsKey(massId))
                    {
                        MassProperties mp = massDictionary[massId];
                        sum = sum + mp.GrossFloorArea;
                    }
                }

                if (sum != 0)
                {
                    far = sum / ap.Area;
                }
                return(far);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to calculate FAR.\n" + ex.Message, "FARCalculator:CalculateFAR", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(far);
            }
        }
コード例 #2
0
        private List <int> FindMass(AreaProperties ap)
        {
            List <int> massIds = new List <int>();

            try
            {
                Outline outline = new Outline(minXYZ, maxXYZ);
                BoundingBoxIntersectsFilter intersectFilter = new BoundingBoxIntersectsFilter(outline);
                BoundingBoxIsInsideFilter   insideFilter    = new BoundingBoxIsInsideFilter(outline);
                LogicalOrFilter             orFilter        = new LogicalOrFilter(intersectFilter, insideFilter);

                FilteredElementCollector collector = new FilteredElementCollector(doc);
                collector.OfCategory(BuiltInCategory.OST_Mass);

                IList <Element> elements = collector.WherePasses(orFilter).ToElements();

                foreach (Element element in elements)
                {
#if RELEASE2015 || RELEASE2016 || RELEASE2017
                    Parameter parameter = element.LookupParameter("Building Function");
#else
                    Parameter parameter = element.get_Parameter("Building Function");
#endif

                    if (null != parameter)
                    {
                        MassProperties mp = new MassProperties(element);
                        if (mp.GrossFloorArea != 0 && null != mp.Centroid)
                        {
                            if (null != ap.BaseFace.Project(mp.Centroid))
                            {
                                mp.AreaId      = ap.AreaId;
                                mp.PlotCode    = ap.PlotCode;
                                mp.DistricCode = ap.DistricCode;
                                if (!massDictionary.ContainsKey(mp.MassId))
                                {
                                    massDictionary.Add(mp.MassId, mp);
                                }
                                massIds.Add(mp.MassId);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Failed to find mass instances within an area object.\n" + ex.Message, "FARCacalculator:FindMass", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            return(massIds);
        }