AnsweredAssumed Answered

Get all start points in a sketch of splines

Question asked by Alec Hearne on Apr 28, 2015
Latest reply on Apr 29, 2015 by Simon Turner

I am trying to get the start points for each spline in a given sketch, and when I run the code below, I get to the "GetCurve" command and get the error "Object variable or With block variable not set." I printed the sketch segment type and got "3", or a spline, which I believe should be compatible with the GetCurve command.


My guess is that the "GetSketchSegments" command doesn't return the correct type of handle to pull curve data, does anyone know the correct way to do this?


Option Explicit


Sub main()

    Dim swApp                    As SldWorks.SldWorks

    Dim swModel                 As SldWorks.ModelDoc2

    Dim swSelMgr                As SldWorks.SelectionMgr

    Dim swSketch                As SldWorks.Sketch

    Dim bRet                       As Boolean

    Dim vSketchSgArr            As Variant

    Dim vSketchSG               As Variant

    Dim swSketchSg              As SldWorks.SketchSegment

    Dim swCurve                 As Object

    Dim skLength                As Double

    Dim startPt                 As SldWorks.SketchPoint

    Dim nStartParam             As Double

    Dim nEndParam               As Double

    Dim bIsClosed               As Boolean

    Dim bIsPeriodic             As Boolean




    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager


    Set swSketch = swModel.GetActiveSketch2


    vSketchSgArr = swSketch.GetSketchSegments()

    For Each vSketchSG In vSketchSgArr

        Set swSketchSg = vSketchSG

        If swSketchSg.GetType = 3 Then

            swCurve = swSketchSg.GetCurve

            bRet = swCurve.GetEndParams(nStartParam, nEndParam, bIsClosed, bIsPeriodic)

            skLength = swCurve.GetLength2(nStartParam, nEndParam)

            startPt = swCurve.Evaluate(nStartParam)

        End If

    Next vSketchSG

End Sub