我正在尝试从
List<XYZ>
创建 XYZ[ ]
或 List<Element>
。 Location
和XYZ
都是Autodesk.Revit.DB命名空间的成员,但似乎没有转换方法。有谁知道其中一个,或者您是否创建了一些可以帮助我的东西?
当然。这里是:
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;
}