2 Replies Latest reply on Feb 25, 2014 8:03 AM by Yong Ning

    How to get distance between plane1 and plane2 with API method.

    Yong Ning

      mm.jpg

      Hope get distance between plane1 and plane2

       

      record Marco

       

      Sub main()

      Set swApp = Application.SldWorks

      Set Part = swApp.ActiveDoc
      Set SelMgr = Part.SelectionManager
      boolstatus = Part.Extension.SelectByID2("Plane2", "PLANE", 0, -0, -0, True, 0, Nothing, 0)
      boolstatus = Part.Extension.SelectByID2("Plane1", "PLANE", 0, -0, -0, True, 0, Nothing, 0)
      End Sub

        • Re: How to get distance between plane1 and plane2
          Radoslav Dimitrov

          What exactly do you mean Ning? You obviously have the distance between them.

           

           

          Well, this is something different now. I'm out of this discussion.

            • Re: How to get distance between plane1 and plane2
              Yong Ning

              0.jpg

              1.jpg

               

              get distance

               

               

              Sub main()

                Dim SwApp As SldWorks.SldWorks, SwModel As ModelDoc2

                Dim SwRefPlane 'As RefPlaneFeatureData

                Set SwApp = Application.SldWorks

                Set SwModel = SwApp.ActiveDoc

                Dim SwSelMgr As SelectionMgr, SwModelDocExt As ModelDocExtension

                Set SwSelMgr = SwModel.SelectionManager

                Set SwModelDocExt = SwModel.Extension

                boolstatus = SwModelDocExt.SelectByID2("Plane1", "PLANE", 0, 0, 0, False, 0, Nothing, swSelectOptionDefault)

                Set Feature = SwSelMgr.GetSelectedObject5(1)

                Set SwRefPlane = Feature.GetDefinition

               

              SwRefPlane.AccessSelections SwModel, Nothing

              Debug.Print SwRefPlane.Distance

              'SwRefPlane.Distance = 0.1

              'Feature.ModifyDefinition SwRefPlane, swPart, Nothing

               

              End Sub

               

              *******************************************

               

              Sub main2()

                 Dim swModel As ModelDoc2, Ss, Ss1

                 Dim swSelMgr As SelectionMgr

                 Dim swRefPt As RefPoint

                 Dim SwFeat As Feature

               

               

               

                 Set swModel = Application.SldWorks.ActiveDoc

                 Set swSelMgr = swModel.SelectionManager

                 swModel.Extension.SelectByID2 "点1", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0

                  Set SwFeat = swSelMgr.GetSelectedObject5(1)

                  Set swRefPt = SwFeat.GetSpecificFeature2

                  Set swRefPtData = SwFeat.GetDefinition

                  Set swMathPt = swRefPt.GetRefPoint

                  ''

                  Ss = swMathPt.ArrayData

                  ''

                 swModel.Extension.SelectByID2 "点2", "DATUMPOINT", 0, 0, 0, False, 0, Nothing, 0

                  Set SwFeat = swSelMgr.GetSelectedObject5(1)

               

                  Set swRefPt = SwFeat.GetSpecificFeature2

                  Set swRefPtData = SwFeat.GetDefinition

                  Set swMathPt = swRefPt.GetRefPoint

                  ''

                  Ss1 = swMathPt.ArrayData

                  xx = (Ss(0) - Ss1(1)) * 1000

                  yy = (Ss(1) - Ss1(1)) * 1000

                  zz = (Ss(2) - Ss1(2)) * 1000

                  Debug.Print Round(xx, 2), Round(yy, 2), Round(zz, 2)

              End Sub