8 Replies Latest reply on Jun 29, 2010 8:20 AM by 1-S3OCKE

    Get points from spline

    saar beno

      Hello,

      i am using solidworks 2010.

      i have spline that is function x(t),y(t),t0,t1, i am drawing him with the function:

      partdoc.skethmanager.createequationspline2(x(t),y(t),t0,t1) (this function work only in solidworks 2010)

      this function return :Iskethspline

      now i need to get points from this spline but i want to get avery some delta (like 0.5 mm) xyz point.

       

      thanks for the help.

        • Re: Get points from spline
          AMCBridge eXperts
          Dim swApp As SldWorks.SldWorks
          Dim swModel As SldWorks.ModelDoc2
          Dim swSelMgr As SldWorks.SelectionMgr
          Dim swSkSpline As SldWorks.SketchSegment
          Dim swCurve As SldWorks.Curve

          Sub main()

              Set swApp = Application.SldWorks
             
              Set swModel = swApp.ActiveDoc
             
              Set swSelMgr = swModel.SelectionManager
             
              Set swSkSpline = swSelMgr.GetSelectedObject6(1, -1)
             
              Set swCurve = swSkSpline.GetCurve
             
              Dim swSkSpl As SldWorks.SketchSpline
              Set swSkSpl = swSkSpline
              Dim vEndPts As Variant
              vEndPts = swSkSpl.GetPoints2()
             
              Dim vStartPt As Variant
              Dim vEndPt As Variant
             
              vStartPt = Array(vEndPts(0).X, vEndPts(0).Y, vEndPts(0).Z)
              vEndPt = Array(vEndPts(1).X, vEndPts(1).Y, vEndPts(1).Z)
             
              Dim vPoints As Variant
             
              vPoints = swCurve.GetTessPts(0.0000001, 0.0000002, vStartPt, vEndPt)
             
              Dim i As Integer
             
              swModel.SketchManager.Insert3DSketch True
             
              swModel.SketchManager.AddToDB = True
             
              For i = 0 To UBound(vPoints) Step 3
                  swModel.SketchManager.CreatePoint vPoints(i), vPoints(i + 1), vPoints(i + 2)
              Next
             
              swModel.SketchManager.AddToDB = False
             
              swModel.SketchManager.Insert3DSketch True
             
          End Sub
            • Re: Get points from spline
              saar beno

              i know this macro this not so good for me.

              i want to declere the delta between every point that i get

                • Re: Get points from spline
                  AMCBridge eXperts

                  Try to evaluate the spline's curve with number of derivative == 1 (X, Y and Z).

                   

                  Find the ratio of required chord length to overal curve size. And use this ratio multipied on UParams (usually from 0 to 1) of the curve while passing the parameters to ICurve::Evaluate2 method.

                   

                  Please let me know if you need more clarifications on this issue.

                    • Re: Get points from spline
                      saar beno

                      hy,

                      i'm sorry but i dont understand what i need to do.

                      again i have a spline that i get from the function "partdoc.skethmanager.createequationspline2"

                      and i want to get points of x,y,z from him many as i wish.

                       

                      thanks allow fot the help!!

                        • Re: Get points from spline
                          saar beno
                          thanks allot for the help**
                            • Re: Get points from spline
                              AMCBridge eXperts

                              Here is what I mean. This macro allows to split a spline by specifying the chord length. It is also possible to rewrite the macro to specify the number of points.

                               

                              Dim swApp As SldWorks.SldWorks
                              Dim swModel As SldWorks.ModelDoc2
                              Dim swSelMgr As SldWorks.SelectionMgr
                              Dim swSketchSeg As SldWorks.SketchSegment
                              Dim swCurve As SldWorks.Curve

                               

                              Sub main()

                               

                                  Set swApp = Application.SldWorks
                                 
                                  Set swModel = swApp.ActiveDoc
                                 
                                  Set swSelMgr = swModel.SelectionManager
                                 
                                  Set swSketchSeg = swSelMgr.GetSelectedObject6(1, -1)
                                 
                                  Set swCurve = swSketchSeg.GetCurve
                                     
                                  Dim vPts As Variant
                                 
                                  vPts = SplitCurveByChord(swCurve, 0.05)
                                         
                                  swModel.ClearSelection2 True
                                 
                                  swModel.SketchManager.Insert3DSketch True
                                 
                                  Dim i As Integer
                                 
                                  For i = 0 To (UBound(vPts) + 1) / 3 - 1
                                 
                                      swModel.SketchManager.CreatePoint vPts(i * 3), vPts(i * 3 + 1), vPts(i * 3 + 2)
                                     
                                  Next
                                 
                                  swModel.SketchManager.Insert3DSketch True
                                         
                              End Sub

                               

                              Function SplitCurveByChord(swCurve As SldWorks.Curve, chordLength As Double) As Variant
                                 
                                  Dim swCurveSpline As SldWorks.Curve
                                  Dim nStartParam As Double
                                  Dim nEndParam As Double
                                  Dim bIsClosed As Boolean
                                  Dim bIsPeriodic As Boolean
                                 
                                  Dim incr As Double
                                  Dim i As Integer
                                  Dim vParam As Variant
                                 
                                  Dim retVal() As Double
                                     
                                  swCurve.GetEndParams nStartParam, nEndParam, bIsClosed, bIsPeriodic
                                 
                                  Dim curveLength As Double
                                  curveLength = swCurve.GetLength3(nStartParam, nEndParam)
                                 
                                  ReDim retVal(CInt(curveLength / chordLength) * 3 - 1)
                                 
                                  incr = (nEndParam - nStartParam) / (curveLength / chordLength)
                                 
                                  For i = 0 To (UBound(retVal) + 1) / 3 - 1
                                 
                                      vParam = swCurve.Evaluate2(nStartParam + i * incr, 1)
                                     
                                      retVal(i * 3) = vParam(0)
                                      retVal(i * 3 + 1) = vParam(1)
                                      retVal(i * 3 + 2) = vParam(2)
                                     
                                  Next
                                 
                                  SplitCurveByChord = retVal
                                 
                              End Function