1 Reply Latest reply on Mar 7, 2018 3:43 AM by Artem Taturevych

    How to use API to get point coordinate with reference to origin in the space rather than with reference to sketch origin?

    Chiao Yang Chang

      The point I get from the code below is (-100,50,0) which is with reference to sketch origin (Fig1).

      How to use API to get point coordinate with reference to origin in the space (Fig2) rather than with reference to sketch origin?

      ------------------------------------------------------------------------------------------------------------------------------

      Option Explicit

      Dim swApp As SldWorks.SldWorks
      Dim swModel As SldWorks.ModelDoc2
      Dim swSelMgr As SldWorks.SelectionMgr

      Dim SelPt As Variant

      Public count As Long

       

      Sub main()

          Set swApp = Application.SldWorks
          Set swModel = swApp.ActiveDoc
          Set swSelMgr = swModel.SelectionManager
         
          SelPt = swSelMgr.GetSelectionPoint2(1, -1)
          Debug.Print "X =" & SelPt(0) * 1000
          Debug.Print "Y =" & SelPt(1) * 1000
          Debug.Print "Z =" & SelPt(2) * 1000

       

      End Sub

      ------------------------------------------------------------------------------------------------------------------------------

       

      [Fig1] point coordinate = (-100,50,0)

       

      [Fig2] point coordinate = (0,50,100)

       

      [Fig3]

        • Re: How to use API to get point coordinate with reference to origin in the space rather than with reference to sketch origin?
          Artem Taturevych

          Option Explicit

           

          Dim swApp As SldWorks.SldWorks

          Dim swModel As SldWorks.ModelDoc2

          Dim swSelMgr As SldWorks.SelectionMgr

           

          Dim SelPt As Variant

          Dim swMathUtils As SldWorks.MathUtility

          Dim swMathPt As SldWorks.MathPoint

           

          Sub main()

           

              Set swApp = Application.SldWorks

              Set swModel = swApp.ActiveDoc

              Set swSelMgr = swModel.SelectionManager

              Set swMathUtils = swApp.GetMathUtility

             

              SelPt = swSelMgr.GetSelectionPoint2(1, -1)

             

              Dim swSketch As SldWorks.Sketch

              Set swSketch = swSelMgr.GetSelectedObject6(1, -1).GetSketch

             

              Dim swXForm As SldWorks.MathTransform

              Set swXForm = swSketch.ModelToSketchTransform.Inverse

             

              Set swMathPt = swMathUtils.CreatePoint(SelPt)

              Set swMathPt = swMathPt.MultiplyTransform(swXForm)

             

              SelPt = swMathPt.ArrayData

             

              Debug.Print "X =" & SelPt(0) * 1000

              Debug.Print "Y =" & SelPt(1) * 1000

              Debug.Print "Z =" & SelPt(2) * 1000

           

          End Sub