AnsweredAssumed Answered

examples of RayIntersections and GetRayIntersectionsPoints

Question asked by Valkyrie Savage on Mar 6, 2013
Latest reply on Mar 9, 2013 by Artem Taturevych

The documentation around these functions is poor at best.

 

Are there any examples of these functions in use?  I didn't find examples in the documentation, and when I tried to use them, it crashed SolidWorks...  this code has camera.rayVectorOrigins that takes a bunch of MathPoints (about 16) and shoves them into a double[] and camera.rayVectorDirections which does the same thing for MathVectors (also about 16).  I didn't get any error messages, just SolidWorks crashes almost immediately after invoking this function.

 

            double[] rayVectorOrigins = camera.rayVectorOrigins();

            double[] rayVectorDirections = camera.rayVectorDirections();

 

 

            object[] bodies = myComponent.GetBodies2((int)swBodyType_e.swSolidBody);

 

 

            alert("we are trying with component " + myComponent.Name);

 

 

            int numIntersectionsFound = swDoc.RayIntersections(bodies,

                                                               rayVectorOrigins,

                                                               rayVectorDirections,

                                                               (int)(swRayPtsOpts_e.swRayPtsOptsTOPOLS | swRayPtsOpts_e.swRayPtsOptsNORMALS),

                                                               .01,

                                                               .01);

 

 

            if (numIntersectionsFound > 0)

            {

                double[] horrifyingReturn = swDoc.GetRayIntersectionsPoints();

                int lengthOfOneReturn = 9;

                for (int i = 0; i < numIntersectionsFound; i++)

                {

                    double bodyIndex = horrifyingReturn[i * lengthOfOneReturn + 0];

                    double rayIndex = horrifyingReturn[i * lengthOfOneReturn + 1];

                    double intersectionType = horrifyingReturn[i * lengthOfOneReturn + 2];

                    double x = horrifyingReturn[i * lengthOfOneReturn + 3];

                    double y = horrifyingReturn[i * lengthOfOneReturn + 4];

                    double z = horrifyingReturn[i * lengthOfOneReturn + 5];

                    double nx = horrifyingReturn[i * lengthOfOneReturn + 6];

                    double ny = horrifyingReturn[i * lengthOfOneReturn + 7];

                    double nz = horrifyingReturn[i * lengthOfOneReturn + 8];

 

 

                    alert("our entire horrifying return " + bodyIndex + "," + rayIndex + "," + intersectionType + "," + x + "," + y + "," + z + "," + nx + "," + ny + "," + nz);

 

 

                    alert("we hit body " + ((Body2)bodies[(int)bodyIndex]).Name + " at " + x + "," + y + "," + z);

 

 

                    visualizeRay("cameraRay-" + randomString(15), camera.rayVectors().ElementAt((int)rayIndex), camera.rayVectorSources().ElementAt((int)rayIndex));

                }

 

            }

Outcomes