Revit 图元.位置到 XYZ

问题描述 投票:0回答:1

我正在尝试从

List<XYZ>
创建
XYZ[ ]
List<Element>
Location
XYZ
都是Autodesk.Revit.DB命名空间的成员,但似乎没有转换方法。有谁知道其中一个,或者您是否创建了一些可以帮助我的东西?

c# location element revit
1个回答
6
投票

当然。这里是:

      List<Element> walls = new List<Element>();

      XYZ p;
      List<XYZ> wall_start_points
        = walls.Select<Element, XYZ>( e => {
          Util.GetElementLocation( out p, e );
            return p; } )
              .ToList<XYZ>();


/// <summary>
        ///     Return a location for the given element using
        ///     its LocationPoint Point property,
        ///     LocationCurve start point, whichever
        ///     is available.
        /// </summary>
        /// <param name="p">Return element location point</param>
        /// <param name="e">Revit Element</param>
        /// <returns>
        ///     True if a location point is available
        ///     for the given element, otherwise false.
        /// </returns>
        public static bool GetElementLocation(
            out XYZ p,
            Element e)
        {
            p = XYZ.Zero;
            var rc = false;
            var loc = e.Location;
            if (null != loc)
            {
                if (loc is LocationPoint lp)
                {
                    p = lp.Point;
                    rc = true;
                }
                else
                {
                    var lc = loc as LocationCurve;

                    Debug.Assert(null != lc,
                        "expected location to be either point or curve");

                    p = lc.Curve.GetEndPoint(0);
                    rc = true;
                }
            }

            return rc;
        }
© www.soinside.com 2019 - 2024. All rights reserved.