Jeremy,
Some corrections to my pseudocode:
- You are right about the view3D. I'm using the 2D view to get the elevation of the view range cut plane. For the ReferenceIntersector, i'm using the standard 3DView (just make sure it does noe have an active section box and that all relevant elements are visible).
var default3DView = new FilteredElementCollector(doc).OfClass(typeof (View3D)).ToElements().Cast<View3D>()
.FirstOrDefault(v => v != null && !v.IsTemplate && v.Name.Equals("{3D}"));
Of course one may create a new 3D view if that works better.
-I forgot to specify that the referenceIntersector should only return Faces beloning to the relevant wall.
var referenceIntersector = new ReferenceIntersector(wall.Id, FindReferenceTarget.Face, default3DView);
- "The wall start point appears twice, the wall end point does not appear at all, and the points are not sorted by proximity:"
The point will get sortet by proximiti when the wall.id is specified to the ReferenceIntersector. Your points are sorted by element, then by proximity.
To get the wall endPoint, it is important to set the "step_outside" in
.Where<ReferenceWithContext>( r => r.Proximity < wallLength + step_outside)
sufficiently large. The first point appears twice probably because "!pointList.First().IsAlmostEqualTo(wallOrigin)" in
if(!pointList.First().IsAlmostEqualTo(wallOrigin))
{
pointList.Insert(0, wallOrigin);
}
will always return true (or !false) and therefore the start point gets inserted. This is because the wallOrigins Z-coordinate is not neccesarily the same as the rayStart z-coordinate. I've changed the code to
Curve c = (wall.Location as LocationCurve).Curve;
var wallStartPoint = new XYZ(c.GetEndPoint(0).X, c.GetEndPoint(0).Y, elevation);
var rayStart = new XYZ(wallStartPoint.X - wallLine.Direction.X, wallStartPoint.Y - wallLine.Direction.Y, wallStartPoint.Z);
[...]
if (!pointList.First().IsAlmostEqualTo(wallStartPoint))
pointList.Insert(0, wallStartPoint);
My code woks quite well now, thank you for the suggestion to use a shooting ray 🙂
Please let me know if anything is unclear.
-Eirik