AnsweredAssumed Answered

Issue with IModelDoc2Extension.RayIntersections in API.

Question asked by Eric Snyder on May 31, 2020
Latest reply on Jun 2, 2020 by Eric Snyder

I need to determine if a ray is entering and exiting a body. What I am trying to determine is just the points on a body that a camera can see. A body could have recesses or other features where a ray could enter, leave and reenter the body. My thought is to cast a ray from a point known to be outside the body and check how many times the ray enters and leaves the body.


I am having issues with Extension.RayIntersections. I have tried the command with both a solid body and a set of faces. I have played with the settings and I get either zero intersections of errors.


Currently things look like this:

object bodies = partDoc.GetBodies2((int)swBodyType_e.swSheetBody, true);

object[] pointArray = new object[] { line.StartPoint.X, line.StartPoint.Y, line.StartPoint.Z };
object[] vectorValues = new object[] { direction.X, direction.Y, direction.Z };
int intersections = ext.RayIntersections(bodies, pointArray, vectorValues, (int)swRayPtsOpts_e.swRayPtsOptsTOPOLS, 0.0000001, 0, false);


Bodies contains one solid body that is a rectangle 500m x500m x 1m. It is massive. I have confirmed that the point is outside the body (not that it matters) and is at:

X: 0.035207883885005481
Y: 0.55562757138497332
Z: 0.43541367664197062

My vector is:

X: -0.060504097452258362
Y: -0.78054254780858767
Z: -0.62216765043834144

so my point starts above the solid and is definitely pointing down toward the solid. There is no way the ray does not intersect. I have used a 3D sketch to draw the start point and the vector, there is no way that the ray is not hitting the solid.


I am getting the massively unhelpful:

System.Runtime.InteropServices.COMException: 'The server threw an exception. (Exception from HRESULT: 0x80010105 

Any suggestions?