Macro for repetitive surface loft operation

Heya;

Facing an interesting challenge; I have a series of 3D spline curves that I need to turn into a series of lofts. Each loft is between two adjacent curves in the series. I have code that generates over a thousand curves which I can load using the ScanTo3D utility. I can then manually create each loft, but given the snail-like performance when the massive amount of data is present, it takes an unreasonable amount of to do it by hand.

So, I figure its high time to jump into the world of writing macros! I have yet to find one that does this task.

From mucking about, I have code that kind of works, in that it selects the curves in the correct order. However, I have so far been unsucessful in creating a loft feature. Has anyone created surface lofts or similar features before? I am sure its something obvious that I am missing, but I am not familiar with either VBA or the Solidworks API...

Attached is part with a few curves as a generic representation of the problem, as well as the code I have so far. The code has two sections, one that uses InsertLoftRefSurface2 and one that uses CreateLoftSurface. Neither one works. Currently just attempting one loft operation, will expand it to the full series once that is working. Any ideas or pointers?

<p><span style="font-family: 'courier new', courier;">Dim swApp As SldWorks.SldWorks</span></p><p><span style="font-family: 'courier new', courier;">Dim swDoc As SldWorks.ModelDoc2</span></p><p><span style="font-family: 'courier new', courier;">Dim swSketch As SldWorks.Sketch</span></p><p><span style="font-family: 'courier new', courier;">Dim vSegs As Variant</span></p><p><span style="font-family: 'courier new', courier;">Dim vSeg As Variant</span></p><p><span style="font-family: 'courier new', courier;">Dim swSeg As SldWorks.SketchSegment</span></p><p><span style="font-family: 'courier new', courier;">Dim swModel As Object</span></p><p></p><p></p><p><span style="font-family: 'courier new', courier;">Sub main()</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Initialize Solidworks objects</span></p><p><span style="font-family: 'courier new', courier;">    Set swApp = Application.SldWorks</span></p><p><span style="font-family: 'courier new', courier;">    Set swDoc = swApp.ActiveDoc</span></p><p><span style="font-family: 'courier new', courier;">    Set swSketch = swDoc.SketchManager.ActiveSketch</span></p><p><span style="font-family: 'courier new', courier;">    Set swModel = swApp.ActiveDoc</span></p><p><span style="font-family: 'courier new', courier;">    Dim swSelMgr As SldWorks.SelectionMgr</span></p><p><span style="font-family: 'courier new', courier;">    Set swSelMgr = swModel.SelectionManager</span></p><p></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Throw an error & exit if not in sketch</span></p><p><span style="font-family: 'courier new', courier;">    If swSketch Is Nothing Then</span></p><p><span style="font-family: 'courier new', courier;">        MsgBox "No sketch active!"</span></p><p><span style="font-family: 'courier new', courier;">        Exit Sub</span></p><p><span style="font-family: 'courier new', courier;">    End If</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Clear selection & get segments from sketch</span></p><p><span style="font-family: 'courier new', courier;">    swDoc.ClearSelection2 True</span></p><p><span style="font-family: 'courier new', courier;">    vSegs = swSketch.GetSketchSegments</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Create points from beginnings of spline curves</span></p><p><span style="font-family: 'courier new', courier;">    Dim Curve As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim PointsObject As Variant</span></p><p><span style="font-family: 'courier new', courier;">    Dim LocStart0 As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim LocStart1 As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim boolstatus As Boolean</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Select curve 0</span></p><p><span style="font-family: 'courier new', courier;">    Set Curve = vSegs(0).GetCurve()</span></p><p><span style="font-family: 'courier new', courier;">    PointsObject = Curve.Evaluate(0)</span></p><p><span style="font-family: 'courier new', courier;">    Set LocStart0 = swDoc.CreatePoint2(PointsObject(0), PointsObject(1), PointsObject(2))</span></p><p><span style="font-family: 'courier new', courier;">    boolstatus = swModel.Extension.SelectByID2("", "SKETCHSEGMENT", PointsObject(0), PointsObject(1), PointsObject(2), False, 1, Nothing, 1)</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Select curve 1</span></p><p><span style="font-family: 'courier new', courier;">    Set Curve = vSegs(1).GetCurve()</span></p><p><span style="font-family: 'courier new', courier;">    PointsObject = Curve.Evaluate(0)</span></p><p><span style="font-family: 'courier new', courier;">    Set LocStart1 = swDoc.CreatePoint2(PointsObject(0), PointsObject(1), PointsObject(2))</span></p><p><span style="font-family: 'courier new', courier;">    boolstatus = swModel.Extension.SelectByID2("", "SKETCHSEGMENT", PointsObject(0), PointsObject(1), PointsObject(2), True, 1, Nothing, 1)</span></p><p></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Create surface loft</span></p><p><span style="font-family: 'courier new', courier;">    swModel.InsertLoftRefSurface2 False, True, False, 1, 0, 0</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' variables for CreateLoftSurface</span></p><p><span style="font-family: 'courier new', courier;">    Dim swModeler As IModeler</span></p><p><span style="font-family: 'courier new', courier;">    Dim CurveArray(2) As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim BBlendClosed As Boolean</span></p><p><span style="font-family: 'courier new', courier;">    Dim BForceCubic As Boolean</span></p><p><span style="font-family: 'courier new', courier;">    Dim GuideCrvArray As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim StartMatchingType As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim EndMatchingType As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim NormalAtStartSection As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim NormalAtEndSection As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim StartMatchingFaceList As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim EndMatchingFaceList As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim DegeneratedStart As Boolean</span></p><p><span style="font-family: 'courier new', courier;">    Dim DegeneratedEnd As Boolean</span></p><p><span style="font-family: 'courier new', courier;">    Dim StartPointOfStartSection As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim StartPointOfEndSection As Object</span></p><p><span style="font-family: 'courier new', courier;">    Dim SectionIndexStart As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim SectionIndexEnd As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim GuideIndexStart As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim GuideIndexEnd As Integer</span></p><p><span style="font-family: 'courier new', courier;">    Dim LoftSurface As Object</span></p><p></p><p></p><p><span style="font-family: 'courier new', courier;">    Set CurveArray(0) = vSegs(0)    ' Sets first curve</span></p><p><span style="font-family: 'courier new', courier;">    Set CurveArray(1) = vSegs(1)    ' Sets second curve</span></p><p><span style="font-family: 'courier new', courier;">    BBlendClosed = False            ' False for non-closed</span></p><p><span style="font-family: 'courier new', courier;">    BForceCubic = False             ' False for not forcing cubic surface</span></p><p><span style="font-family: 'courier new', courier;">    Set GuideCrvArray = Nothing     ' Don't have a guide curve</span></p><p><span style="font-family: 'courier new', courier;">    StartMatchingType = 0           ' Match none</span></p><p><span style="font-family: 'courier new', courier;">    EndMatchingType = 0             ' Match none</span></p><p><span style="font-family: 'courier new', courier;">    Set NormalAtStartSection = Nothing  ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    Set NormalAtEndSection = Nothing    ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    Set StartMatchingFaceList = Nothing ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    Set EndMatchingFaceList = Nothing   ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    DegeneratedStart = False            ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    DegeneratedEnd = False              ' Not used</span></p><p><span style="font-family: 'courier new', courier;">    Set StartPointOfStartSection = LocStart0    'Start point of curve 0</span></p><p><span style="font-family: 'courier new', courier;">    Set StartPointOfEndSection = LocStart1      'Start point of curve 1</span></p><p><span style="font-family: 'courier new', courier;">    SectionIndexStart = 0</span></p><p><span style="font-family: 'courier new', courier;">    SectionIndexEnd = 1</span></p><p><span style="font-family: 'courier new', courier;">    GuideIndexStart = -1</span></p><p><span style="font-family: 'courier new', courier;">    GuideIndexEnd = -1</span></p><p></p><p><span style="font-family: 'courier new', courier;">    ' Create the surface loft</span></p><p><span style="font-family: 'courier new', courier;">    Set swModeler = swApp.GetModeler</span></p><p><span style="font-family: 'courier new', courier;">    Set LoftSurface = swModeler.CreateLoftSurface(CurveArray, BBlendClosed, BForceCubic, GuideCrvArray, StartMatchingType, EndMatchingType, NormalAtStartSection, NormalAtEndSection, StartMatchingFaceList, EndMatchingFaceList, DegeneratedStart, DegeneratedEnd, StartPointOfStartSection, StartPointOfEndSection, SectionIndexStart, SectionIndexEnd, GuideIndexStart, GuideIndexEnd)</span></p><p></p><p></p><p><span style="font-family: 'courier new', courier;">End Sub</span></p>
SolidworksApi macros