AnsweredAssumed Answered

Selecting boundary lines for a trim inside operation

Question asked by Harold Black on Mar 19, 2018
Latest reply on Mar 19, 2018 by Harold Black

I have a spline where I need to trim all the vertical lines below it. I figure the easiest approach would be to create a horizontal line and use the spline and horizontal line as boundary entities for "Trim away inside". How would I loop through all my sketch segments to select the boundary entities and then the entities to trim? For the spline I can search for swSketchSeg.GetType and see if it is swSketchSpline, but this sort of comparison would not work for the straight lines. Any help would be appreciated. I've attached a screenshot of what my code produces thus far. The values for minEl and maxEl will have to be changed depending on what your min and max y values are for your spline. The vertical lines should extend past the spline above and below. Change the number of divisions according to the length of your spline.



Sub main()



    Dim swApp                       As SldWorks.SldWorks

    Dim swModel                     As SldWorks.ModelDoc2

    Dim swSelMgr                    As SldWorks.SelectionMgr

    Dim swSketchMgr                 As SldWorks.SketchManager

    Dim swSketchSeg                 As SldWorks.SketchSegment

    Dim swSketch                    As SldWorks.Sketch

    Dim swCurve                     As SldWorks.Curve

    Dim nStartParam                 As Double

    Dim nEndParam                   As Double

    Dim bIsClosed                   As Boolean

    Dim bIsPeriodic                 As Boolean

    Dim vStart                      As Variant

    Dim vEnd                        As Variant

    Dim LStart                      As Variant

    Dim LEnd                        As Variant

    Dim vSegs                       As Variant

    Dim Seg                         As Variant

    Dim bRet                        As Boolean

    Dim minEl As Double

    Dim maxEl As Double

    Dim divisions As Integer

    Dim spacing As Double

    Dim myFeature As SldWorks.Feature

    Dim boolstatus As Boolean

    Dim xstart As Double

    Dim xend As Double


    Set swApp = Application.SldWorks

    Set swModel = swApp.ActiveDoc

    Set swSelMgr = swModel.SelectionManager

    Set swSketchSeg = swSelMgr.GetSelectedObject5(1)

    Set swCurve = swSketchSeg.GetCurve

    Set swSketchMgr = swModel.SketchManager

    Set swSketch = swModel.SketchManager.ActiveSketch


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


    Debug.Assert bRet


    minEl = -10 / 1000

    maxEl = 60 / 1000

    divisions = 7


    vStart = swCurve.Evaluate(nStartParam)

    vEnd = swCurve.Evaluate(nEndParam)

    spacing = (Abs(vStart(0) - vEnd(0))) / divisions

    xstart = vStart(0) + spacing / 2

    xend = vEnd(0)


    swModel.CreateLineVB xstart - spacing / 2, minEl, 0#, xend, minEl, 0#


    'Create first centerline and pattern it

    swModel.CreateLineVB xstart, minEl, 0#, xstart, maxEl, 0#

    boolstatus = swSketchMgr.CreateLinearSketchStepAndRepeat(divisions, 1, spacing, 0.01, 0, 1.5707963267949, "", False, False, False, False, False)


    'Select all but a SPLINE sketch segment and color it red

    vSegs = swSketch.GetSketchSegments

    For Each Seg In vSegs

        Set swSketchSeg = Seg

        If swSketchSeg.GetType <> swSketchSPLINE Then

            swSketchSeg.Select True

            swSketchSeg.Color = vbRed

        End If

    Next Seg


    Debug.Print String(255, vbNewLine)


    Debug.Print spacing

    Debug.Print "  Start Pt     = (" & vStart(0) * 1000# & ", " & vStart(1) * 1000# & ", " & vStart(2) * 1000# & ") mm"

    Debug.Print "  End   Pt     = (" & vEnd(0) * 1000# & ", " & vEnd(1) * 1000# & ", " & vEnd(2) * 1000# & ") mm"


End Sub