示例#1
0
        /// <summary>
        ///     Gets the element's projection area.
        /// </summary>
        /// <param name="elm">A element</param>
        /// <exception cref="T:Autodesk.Revit.Exceptions.ArgumentNullException">The input element is invalid.</exception>
        /// <returns>Returns projection area.</returns>
        public static double GetShadowArea(this Element elm)
        {
            if (elm is null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            if (!elm.IsValidObject)
            {
                throw new InvalidDataException(nameof(elm));
            }

            if (elm.Id.IntegerValue == -1)
            {
                throw new InvalidDataException(nameof(elm));
            }

            var areas = new List <double>();
            var geo   = elm.get_Geometry(new Options());

            foreach (var instance in geo.Select(s => s as GeometryInstance))
            {
                if (instance is null)
                {
                    continue;
                }

                foreach (var item in instance.GetInstanceGeometry())
                {
                    var solid = item as Solid;

                    if (null == solid || solid.Faces.Size <= 0)
                    {
                        continue;
                    }

                    var plane = XYZ.BasisZ.CreatePlane(XYZ.Zero);

                    ExtrusionAnalyzer analyzer;

                    try
                    {
                        analyzer = ExtrusionAnalyzer.Create(solid, plane, XYZ.BasisZ);
                    }
                    catch
                    {
                        continue;
                    }

                    if (analyzer is null)
                    {
                        continue;
                    }

                    areas.Add(analyzer.GetExtrusionBase().Area);
                }
            }

            return(areas.Max());
        }
示例#2
0
        /// <summary>
        /// Gets the element's projection area.
        /// </summary>
        /// <param name="elm">A element</param>
        /// <remarks>Returns projection area, that area unit is square meter.</remarks>
        /// <exception cref="T:Autodesk.Revit.Exceptions.ArgumentNullException">The input element is invalid.</exception>
        /// <returns>Returns projection area.</returns>
        public static double GetShadowArea(this Element elm)
        {
            if (elm == null)
            {
                throw new ArgumentNullException(nameof(elm));
            }

            var areas = new List <double>();
            var geo   = elm.get_Geometry(new Options());

            foreach (var instance in geo.Select(s => s as GeometryInstance))
            {
                if (instance == null)
                {
                    continue;
                }

                foreach (var item in instance.GetInstanceGeometry())
                {
                    var solid = item as Solid;

                    if (null == solid || solid.Faces.Size <= 0)
                    {
                        continue;
                    }

                    var plane = Plane.CreateByOriginAndBasis(XYZ.Zero, XYZ.BasisX, XYZ.BasisY);

                    ExtrusionAnalyzer analyzer;

                    try
                    {
                        analyzer = ExtrusionAnalyzer.Create(solid, plane, XYZ.BasisZ);
                    }
                    catch
                    {
                        continue;
                    }

                    if (analyzer == null)
                    {
                        continue;
                    }

                    areas.Add(analyzer.GetExtrusionBase().Area *FT2_TO_M2);
                }
            }

            return(areas.Max());
        }
示例#3
0
        /// <summary>
        /// Add all plan view boundary loops from
        /// given solid to the list of loops.
        /// The creation application argument is used to
        /// reverse the extrusion analyser output curves
        /// in case they are badly oriented.
        /// </summary>
        /// <returns>Number of loops added</returns>
        static int AddLoops(
            Autodesk.Revit.Creation.Application creapp,
            JtLoops loops,
            GeometryObject obj,
            ref int nExtrusionAnalysisFailures)
        {
            int nAdded = 0;

            Solid solid = obj as Solid;

            if (null != solid &&
                0 < solid.Faces.Size)
            {
                //Plane plane = new Plane(XYZ.BasisX,
                //  XYZ.BasisY, XYZ.Zero); // 2016

                Plane plane = Plane.CreateByOriginAndBasis(
                    XYZ.Zero, XYZ.BasisX, XYZ.BasisY); // 2017

                ExtrusionAnalyzer extrusionAnalyzer = null;

                try
                {
                    extrusionAnalyzer = ExtrusionAnalyzer.Create(
                        solid, plane, XYZ.BasisZ);
                }
                catch (Autodesk.Revit.Exceptions
                       .InvalidOperationException)
                {
                    ++nExtrusionAnalysisFailures;
                    return(nAdded);
                }

                Face face = extrusionAnalyzer
                            .GetExtrusionBase();

                loops.Add(GetLoop(creapp, face));

                ++nAdded;
            }
            return(nAdded);
        }
示例#4
0
        private static IEnumerable <CurveLoop> GetCountours(
            Solid solid,
            Element element)
        {
            try
            {
                var plane = Plane.CreateByNormalAndOrigin(
                    XYZ.BasisZ, element.get_BoundingBox(null).Min);

                var analyzer = ExtrusionAnalyzer.Create(
                    solid, plane, XYZ.BasisZ);

                var face = analyzer.GetExtrusionBase();

                return(face.GetEdgesAsCurveLoops());
            }
            catch (InvalidOperationException)
            {
                return(Enumerable.Empty <CurveLoop>());
            }
        }
        /// <summary>
        /// Retrieve all plan view boundary loops from
        /// all solids of the given element geometry
        /// united together.
        /// </summary>
        internal static JtLoops GetPlanViewBoundaryLoopsGeo(
            Autodesk.Revit.Creation.Application creapp,
            GeometryElement geo,
            ref int nFailures)
        {
            Solid union = null;

            Plane plane = new Plane(XYZ.BasisX,
                                    XYZ.BasisY, XYZ.Zero);

            foreach (GeometryObject obj in geo)
            {
                Solid solid = obj as Solid;

                if (null != solid &&
                    0 < solid.Faces.Size)
                {
                    // Some solids, e.g. in the standard
                    // content 'Furniture Chair - Office'
                    // cause an extrusion analyser failure,
                    // so skip adding those.

                    try
                    {
                        ExtrusionAnalyzer extrusionAnalyzer
                            = ExtrusionAnalyzer.Create(
                                  solid, plane, XYZ.BasisZ);
                    }
                    catch (Autodesk.Revit.Exceptions
                           .InvalidOperationException)
                    {
                        solid = null;
                        ++nFailures;
                    }

                    if (null != solid)
                    {
                        if (null == union)
                        {
                            union = solid;
                        }
                        else
                        {
                            try
                            {
                                union = BooleanOperationsUtils
                                        .ExecuteBooleanOperation(union, solid,
                                                                 BooleanOperationsType.Union);
                            }
                            catch (Autodesk.Revit.Exceptions
                                   .InvalidOperationException)
                            {
                                ++nFailures;
                            }
                        }
                    }
                }
            }

            JtLoops loops = new JtLoops(1);

            AddLoops(creapp, loops, union, ref nFailures);

            return(loops);
        }