Ray intersection is one of the most commonly used nodes for collision calculation and distance measurement in many 3D models. However, when using the ray method and setting target to element, you will find that two identical values appear.
Using floor distance as an example, two different values appear in the figure below. After I modified the slab thickness, I found that it was exactly the distance of the slab thickness. It can be guessed that the ray method determines intersection for both faces, but this does not match our need for one value per element output. Here we need to re-judge or directly take the minimum value to get the clear height.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var intersector = new ReferenceIntersector(classFilter, FindReferenceTarget.Element, modelView);
intersector.FindReferencesInRevitLinks = true;

var result = intersector.Find(origin, -XYZ.BasisZ);

foreach (var context in result)
{
var ele = context.GetReference();
var revitLinkInstance = _document.GetElement(ele) as RevitLinkInstance;
var linkDoc = revitLinkInstance.GetLinkDocument();

var eleName = linkDoc.GetElement(ele.LinkedElementId);

var eleNmae = _document.GetElement(ele).Name;


MessageBox.Show(result.Count.ToString() + "-" + eleNmae + $"{eleName.GetType()}" + "-" + context.Proximity * 304.8);
}

Image Description
Image Description

Later I changed the method to get the nearest face to avoid this happening, but encountering other situations may require looping through the context values for re-filtering.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

var result = intersector.FindNearest(origin, -XYZ.BasisZ);


var stringbuild = new StringBuilder();

var ele = result.GetReference();
var revitLinkInstance = _document.GetElement(ele) as RevitLinkInstance;
var linkDoc = revitLinkInstance?.GetLinkDocument();

var eleName = linkDoc?.GetElement(ele.LinkedElementId);

stringbuild.Append(
$"ElementType : {eleName?.GetType()} , ElementLinkId:{ele.LinkedElementId} ,Proximity : {result.Proximity * 304.8} \r\n");

MessageBox.Show(stringbuild.ToString());