0 Replies Latest reply on Jun 18, 2014 8:12 PM by Alex Beaulier

    Can anyone modify this code for the boundary surface tool with lines?

    Alex Beaulier

      I have a ton of line segments in one sketch for a solidworks part. I need to modify this macro below so I can have the boundary surface tool select every single line from one side to another. All the lines are in order from one side to another. I don't know how to modify the code so instead of curves, it uses linesegments and instead of using the surface loft, it will use the boundary surface.


      Basically, I need a code that will

      *create a boundary surface using line segments from a single sketch




      Here's the code


      Dim swApp As SldWorks.SldWorks

      Dim swDoc As SldWorks.ModelDoc2

      Dim swSketch As SldWorks.Sketch

      Dim vSegs As Variant

      Dim vSeg As Variant

      Dim swSeg As SldWorks.SketchSegment

      Dim swModel As Object



      Sub main()


          ' Initialize Solidworks objects

          Set swApp = Application.SldWorks

          Set swDoc = swApp.ActiveDoc

          Set swSketch = swDoc.SketchManager.ActiveSketch

          Set swModel = swApp.ActiveDoc

          Dim swSelMgr As SldWorks.SelectionMgr

          Set swSelMgr = swModel.SelectionManager



          ' Throw an error & exit if not in sketch

          If swSketch Is Nothing Then

              MsgBox "No sketch active!"

              Exit Sub

          End If


          ' Clear selection & get segments from sketch

          swDoc.ClearSelection2 True

          vSegs = swSketch.GetSketchSegments


          ' Create points from beginnings of spline curves

          Dim Curve As Object

          Dim PointsObject As Variant

          Dim LocStart0 As Object

          Dim LocStart1 As Object

          Dim boolstatus As Boolean


          ' Select curve 0

          Set Curve = vSegs(0).GetCurve()

          PointsObject = Curve.Evaluate(0)

          Set LocStart0 = swDoc.CreatePoint2(PointsObject(0), PointsObject(1), PointsObject(2))

          boolstatus = swModel.Extension.SelectByID2("", "SKETCHSEGMENT", PointsObject(0), PointsObject(1), PointsObject(2), False, 1, Nothing, 1)


          ' Select curve 1

          Set Curve = vSegs(1).GetCurve()

          PointsObject = Curve.Evaluate(0)

          Set LocStart1 = swDoc.CreatePoint2(PointsObject(0), PointsObject(1), PointsObject(2))

          boolstatus = swModel.Extension.SelectByID2("", "SKETCHSEGMENT", PointsObject(0), PointsObject(1), PointsObject(2), True, 1, Nothing, 1)



          ' Create surface loft

          swModel.InsertLoftRefSurface2 False, True, False, 1, 0, 0


          ' variables for CreateLoftSurface

          Dim swModeler As IModeler

          Dim CurveArray(2) As Object

          Dim BBlendClosed As Boolean

          Dim BForceCubic As Boolean

          Dim GuideCrvArray As Object

          Dim StartMatchingType As Integer

          Dim EndMatchingType As Integer

          Dim NormalAtStartSection As Object

          Dim NormalAtEndSection As Object

          Dim StartMatchingFaceList As Object

          Dim EndMatchingFaceList As Object

          Dim DegeneratedStart As Boolean

          Dim DegeneratedEnd As Boolean

          Dim StartPointOfStartSection As Object

          Dim StartPointOfEndSection As Object

          Dim SectionIndexStart As Integer

          Dim SectionIndexEnd As Integer

          Dim GuideIndexStart As Integer

          Dim GuideIndexEnd As Integer

          Dim LoftSurface As Object



          Set CurveArray(0) = vSegs(0)    ' Sets first curve

          Set CurveArray(1) = vSegs(1)    ' Sets second curve

          BBlendClosed = False            ' False for non-closed

          BForceCubic = False             ' False for not forcing cubic surface

          Set GuideCrvArray = Nothing     ' Don't have a guide curve

          StartMatchingType = 0           ' Match none

          EndMatchingType = 0             ' Match none

          Set NormalAtStartSection = Nothing  ' Not used

          Set NormalAtEndSection = Nothing    ' Not used

          Set StartMatchingFaceList = Nothing ' Not used

          Set EndMatchingFaceList = Nothing   ' Not used

          DegeneratedStart = False            ' Not used

          DegeneratedEnd = False              ' Not used

          Set StartPointOfStartSection = LocStart0    'Start point of curve 0

          Set StartPointOfEndSection = LocStart1      'Start point of curve 1

          SectionIndexStart = 0

          SectionIndexEnd = 1

          GuideIndexStart = -1

          GuideIndexEnd = -1


          ' Create the surface loft

          Set swModeler = swApp.GetModeler

          Set LoftSurface = swModeler.CreateLoftSurface(CurveArray, BBlendClosed, BForceCubic, GuideCrvArray, StartMatchingType, EndMatchingType, NormalAtStartSection, NormalAtEndSection, StartMatchingFaceList, EndMatchingFaceList, DegeneratedStart, DegeneratedEnd, StartPointOfStartSection, StartPointOfEndSection, SectionIndexStart, SectionIndexEnd, GuideIndexStart, GuideIndexEnd)



      End Sub