3 Replies Latest reply on Mar 19, 2017 9:00 PM by Raghvendra Bhargava

    The point from GetProjectedPointOn is on the extend face? 

    Chi-Shin Wang

      How to determine whether a point is inside a body by using Solidworks api?

      I have same question with this link

      I try this link's solution

      but the point get from GetProjectedPointOn is on the extend face

      The point from the image below is the projected point

      but i get two should not exist point

      I do not know the GetProjectedPointOn can get the point even this point is not on the face.

      Is there any solution to solve this problem?

      Thanks.

      擷取.PNG

        • Re: The point from GetProjectedPointOn is on the extend face? 
          Raghvendra Bhargava

          Hi Wang,

           

          If point is on the face Try this:

           

          Dim swApp As SldWorks.SldWorks

          Dim Part As ModelDoc2

          Dim mathUtils As MathUtility

          Dim boolstatus As Boolean

           

          Sub main()

          Set swApp = Application.SldWorks

          Set mathUtils = swApp.GetMathUtility()

          Set Part = swApp.ActiveDoc

           

          boolstatus = Part.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0) 'Chnage with your Point selection

          Dim swPt  As SketchPoint

          Set swPt = Part.SelectionManager.GetSelectedObject6(1, -1)

          Dim Mpt As MathPoint

          Dim swPoint(2) As Double

          Dim swArr As Variant

          swPoint(0) = swPt.X

          swPoint(1) = swPt.Y

          swPoint(2) = swPt.Z

          swArr = swPoint

          Set Mpt = mathUtils.CreatePoint(swArr)

           

           

          Dim rayVector As MathVector

          Dim pointdir(2) As Double

          Dim vArr As Variant

          pointdir(0) = 1

          pointdir(1) = 1

          pointdir(2) = 1

          vArr = pointdir

          Set rayVector = mathUtils.CreateVector(vArr)

          boolstatus = Part.Extension.SelectByID2("", "FACE", -0.121708781460484, -1.12215848405413E-02, 9.99999999970669E-03, False, 0, Nothing, 0) 'Chnage with your Face selection

          Dim face As Face2

          Set face = Part.SelectionManager.GetSelectedObject6(1, -1)

           

          Dim InterSectpoint As MathPoint

          Set InterSectpoint = face.GetProjectedPointOn(Mpt, rayVector)

          If InterSectpoint Is Nothing Then swApp.SendMsgToUser "Point is not on the selected face"

           

          Part.ClearSelection2 True

          End Sub

            • Re: The point from GetProjectedPointOn is on the extend face? 
              Chi-Shin Wang

              Hi RB,

              Thank you for reply.

              I think check whether the point is on the face is not my solution.

              My question is even if the point absolutely will not have projected point,

              the GetProjectedPointOn method will successful execution and return a point.

              But I'm really appreciate that you reply my question.

              Hope you have a good day.

                • Re: The point from GetProjectedPointOn is on the extend face? 
                  Raghvendra Bhargava

                  Hi Wang,

                  This code will take the point on surface, so if your point intersect on the surface it will return you a Intersection point.

                   

                  Dim swApp As SldWorks.SldWorks

                  Dim Part As ModelDoc2

                  Dim mathUtils As MathUtility

                  Dim boolstatus As Boolean

                   

                  Sub main()

                  Set swApp = Application.SldWorks

                  Set mathUtils = swApp.GetMathUtility()

                  Set Part = swApp.ActiveDoc

                   

                  boolstatus = Part.Extension.SelectByID2("Point1", "SKETCHPOINT", 0, 0, 0, False, 0, Nothing, 0) 'Chnage with your Point selection

                  Dim swPt  As SketchPoint

                  Set swPt = Part.SelectionManager.GetSelectedObject6(1, -1)

                  Dim Mpt As MathPoint

                  Dim swPoint(2) As Double

                  Dim swArr As Variant

                  swPoint(0) = swPt.X

                  swPoint(1) = swPt.Y

                  swPoint(2) = swPt.Z

                  swArr = swPoint

                  Set Mpt = mathUtils.CreatePoint(swArr)

                   

                   

                  Dim rayVector As MathVector

                  Dim pointdir(2) As Double

                  Dim vArr As Variant

                  pointdir(0) = 1

                  pointdir(1) = 1

                  pointdir(2) = 1

                  vArr = pointdir

                  Set rayVector = mathUtils.CreateVector(vArr)

                  boolstatus = Part.Extension.SelectByID2("", "FACE", -8.13009621262495E-02, 0.035105720086051, 9.99999999970669E-03, False, 0, Nothing, 0) 'Chnage with your Face selection

                  Dim face As Face2

                  Set face = Part.SelectionManager.GetSelectedObject6(1, -1)

                  '------------------

                  Dim surface As surface

                  Set surface = face.GetSurface

                  '--------------------------------

                   

                  Dim InterSectpoint As MathPoint

                  Set InterSectpoint = surface.GetProjectedPointOn(Mpt, rayVector)

                  If InterSectpoint Is Nothing Then swApp.SendMsgToUser "Point is not on the selected face"

                   

                  Part.ClearSelection2 True

                  End Sub