- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I'm trying to get the floor to floor/roof height (depending on whether there's another floor above the room or a roof) of rooms in Revit, I've tried to implement ray intersections following the reference intersector class documentation: https://www.revitapidocs.com/2015/d28155ae-817b-1f31-9c3f-c9c6a28acc0d.htm
However whilst debugging with breakpoints, I've found the reference.global point returned on all my intersections has a z coordinate of 0. Is there something I'm doing wrong here, is there a way to get this z coordinate?
One workaround I've thought of so far would to be to find the element and use its bounding box. But in the case of a sloping roof this would not give me the true value.
public double GetFloorToRoofHeight()
{
// Find a 3D view to use for the ReferenceIntersector constructor
FilteredElementCollector collector = new FilteredElementCollector(room.Document);
Func<View3D, bool> isNotTemplate = v3 => !(v3.IsTemplate);
View3D view3D = collector.OfClass(typeof(View3D)).Cast<View3D>().First<View3D>(isNotTemplate);
// Use the center of the room bounding box as the start point.
XYZ center = boundingBox.Min.Add(boundingBox.Max).Multiply(0.5);
XYZ up = new XYZ(0, 0, 1);
XYZ down = new XYZ(0, 0, -1);
ElementClassFilter filter = new ElementClassFilter(typeof(Floor));
ReferenceIntersector refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.Face, view3D);
ReferenceWithContext referenceWithContext = refIntersector.FindNearest(center, down);
Reference reference = referenceWithContext.GetReference();
XYZ intersectionFloor = reference.GlobalPoint;
filter = new ElementClassFilter(typeof(Floor));
refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.Face, view3D);
referenceWithContext = refIntersector.FindNearest(center, up);
//if we found floor above we use it for height otherwise we need to search for a roof
if (referenceWithContext != null)
{
Reference reference2 = referenceWithContext.GetReference();
XYZ intersectionFloorUp = reference.GlobalPoint;
Debug.WriteLine(Line.CreateBound(center, intersectionFloorUp).Length);
return intersectionFloorUp.Z - intersectionFloor.Z;
}
filter = new ElementClassFilter(typeof(RoofBase));
refIntersector = new ReferenceIntersector(filter, FindReferenceTarget.Face, view3D);
referenceWithContext = refIntersector.FindNearest(center, up);
if (referenceWithContext == null)
{
return 0;
}
Reference reference3 = referenceWithContext.GetReference();
XYZ intersectionRoof = reference.GlobalPoint;
Debug.WriteLine(Line.CreateBound(center, intersectionRoof).Length);
return intersectionRoof.Z - intersectionFloor.Z;
}
Solved! Go to Solution.