Geoff Overfield Geoff Overfield - 17 days ago 7
C# Question

Revit Element.Location to XYZ

I'm trying to create a

List<XYZ>
or
XYZ[ ]
from a
List<Element>
.  Both
Location
and
XYZ
are members of the Autodesk.Revit.DB namespace, but there doesn't seem to be a conversion method.  Does anyone know of one, or have you created something that may be able to help me out?

Answer

Sure. Here goes:

  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>();

This uses the GetElementLocation method defined in The Building Coder samples Util class:

https://github.com/jeremytammik/the_building_coder_samples/blob/master/BuildingCoder/BuildingCoder/Util.cs#L873-L910

Comments