ThroughCurvesBuilder Error

Hi all,
I have been trying create a journal by recording and editing it to create Throughcurves surface.
Steps:
1. Select the first datum plane where the surface starts.
2. Get the use input for number of planes and offset value.
3. Select the dumb surface to be recreated
4. Create section cuts with all the planes.
5. Create through curves surface.

I have the code below. I am getting the error of " invalid feature parameter" at the line feature1 = throughCurvesBuilder1.CommitFeature() . But this is coming from recorded journal. Can some one help me? I am just started to learn coding in NX.

Thanks in advance.
Regards,
Nataraj

' NX 8.5.0.23
' Journal created by Nataraj on Thu Apr 28 17:57:38 2016 India Standard Time
'
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpenUI

Module NXJournal
Sub Main (ByVal args() As String)

Dim theSession As Session = Session.GetSession()
Dim workPart As Part = theSession.Parts.Work

Dim displayPart As Part = theSession.Parts.Display
Dim lw As ListingWindow = theSession.ListingWindow

' ----------------------------------------------
' Menu: Insert->Datum/Point->Datum Plane...
' ----------------------------------------------
Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

Dim nullFeatures_Feature As Features.Feature = Nothing

If Not workPart.Preferences.Modeling.GetHistoryMode Then
Throw(New Exception("Create or edit of a Feature was recorded in History Mode but playback is in History-Free Mode."))
End If

Dim unit1 As Unit = CType(workPart.UnitCollection.FindObject("MilliMeter"), Unit)
Dim expression1 As Expression
expression1 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)
Dim expression2 As Expression
expression2 = workPart.Expressions.CreateSystemExpressionWithUnits("0", unit1)

' ----------------------------------------------
' Getting the First Plane for offset
' ----------------------------------------------

Dim mySelectedObject As NXObject
Dim mySelectedObject1 As NXObject

Dim myoffset As Double = 0
Dim myoffsetnew As Double = 0
Dim mynumplane As Integer = 0
Dim i As Integer

SelectAnObject(mySelectedObject)
mynumplane = NXInputBox.GetInputString("Enter number of planes","Plane Building", "Count")
myoffset = NXInputBox.GetInputString("Enter plane offset values","Plane Building", "Offset")

'lw.Open
'lw.WriteLine("Object Tag: " & mySelectedObject.Tag )
'lw.WriteLine("Object Type: " & mySelectedObject.GetType.ToString)
'lw.WriteLine("Object Tag: " & datumPlane1.GetTitle.ToString)
'lw.WriteLine("")
'lw.Close

SelectSurface(mySelectedObject1)

Dim geom1(0) As NXObject
geom1(0) = mySelectedObject

Dim geom2(0) As NXObject
geom2(0) = mySelectedObject1

' ----------------------------------------------
' Creating a Surface by Through Curve
' ----------------------------------------------
Dim throughCurvesBuilder1 As Features.ThroughCurvesBuilder
throughCurvesBuilder1 = workPart.Features.CreateThroughCurvesBuilder(nullFeatures_Feature)

throughCurvesBuilder1.PreserveShape = False
theSession.SetUndoMarkName(markId1, "Through Curves Dialog")
throughCurvesBuilder1.Alignment.AlignCurve.DistanceTolerance = 0.0254
throughCurvesBuilder1.Alignment.AlignCurve.ChainingTolerance = 0.02413
throughCurvesBuilder1.SectionTemplateString.DistanceTolerance = 0.0254
throughCurvesBuilder1.SectionTemplateString.ChainingTolerance = 0.02413
throughCurvesBuilder1.Alignment.AlignCurve.AngleTolerance = 0.5
throughCurvesBuilder1.SectionTemplateString.AngleTolerance = 0.5
'Dim section1 As Section
'section1 = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)

For i = 0 To mynumplane-1

' ----------------------------------------------
' Creating the array of planes
' ----------------------------------------------
Dim datumPlaneBuilder1 As Features.DatumPlaneBuilder
datumPlaneBuilder1 = workPart.Features.CreateDatumPlaneBuilder(nullFeatures_Feature)
Dim plane1 As Plane
plane1 = datumPlaneBuilder1.GetPlane()
'theSession.SetUndoMarkName(markId1, "Datum Plane Dialog")
plane1.SetUpdateOption(SmartObject.UpdateOption.WithinModeling)
plane1.SetMethod(PlaneTypes.MethodType.Distance)
plane1.SetGeometry(geom1)
plane1.SetFlip(False)
plane1.SetReverseSide(False)
Dim expressionx As Expression
expressionx = plane1.Expression
myoffsetnew = myoffsetnew + myoffset
expressionx.RightHandSide = myoffsetnew
Dim datumPlaneFeature1 As Features.DatumPlaneFeature = datumPlaneBuilder1.CommitFeature()
Dim datumPlane1 As DatumPlane
datumPlane1 = datumPlaneFeature1.DatumPlane
plane1.RemoveOffsetData()
datumPlaneBuilder1.Destroy()

' ----------------------------------------------
' Creating Section cuts
' ----------------------------------------------
'Dim markId4 As Session.UndoMarkId
'markId4 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")
Dim sectionCurveBuilder1 As Features.SectionCurveBuilder
sectionCurveBuilder1 = workPart.Features.CreateSectionCurveBuilder(nullFeatures_Feature)
sectionCurveBuilder1.CurveFitData.Tolerance = 0.0254
sectionCurveBuilder1.CurveFitData.AngleTolerance = 0.5
sectionCurveBuilder1.ChordalTolerance = 0.0254
'theSession.SetUndoMarkName(markId4, "Section Curve Dialog")
Dim added1 As Boolean
added1 = sectionCurveBuilder1.ObjectsToSection.Add(mySelectedObject1)
Dim added2 As Boolean
added2 = sectionCurveBuilder1.SectionPlanes.Add(datumPlane1)
Dim nXObject1 As NXObject
nXObject1 = sectionCurveBuilder1.Commit()
'theSession.DeleteUndoMark(markId6, Nothing)
'theSession.SetUndoMarkName(markId4, "Section Curve")
sectionCurveBuilder1.Destroy()

' ----------------------------------------------
' Creating Surface
' ----------------------------------------------
Dim section1(mynumplane-1) As Section

section1(i) = workPart.Sections.CreateSection(0.02413, 0.0254, 0.5)
throughCurvesBuilder1.SectionsList.Append(section1(i))
section1(i).SetAllowedEntityTypes(Section.AllowTypes.CurvesAndPoints)

Dim features1(0) As Features.Feature
'Dim sectionCurve1 As Features.SectionCurve = CType(workPart.Features.FindObject("SECTION_CURVES(120)"), Features.SectionCurve)
Dim sectionCurve1 As Features.SectionCurve
sectionCurve1 = nXObject1

features1(0) = sectionCurve1
'Dim line1 As Line = CType(sectionCurve1.FindObject("CURVE 1 {3 (-10,-2.3539044875025,50)}"), Line)
section1(i).AllowSelfIntersection(False)

Next

'Dim nXObject2 As NXObject
'nXObject2 = throughCurvesBuilder1.Commit()

Dim markId9 As Session.UndoMarkId
markId9 = theSession.SetUndoMark(Session.MarkVisibility.Invisible, "Through Curves")

Dim feature1 As Features.Feature
feature1 = throughCurvesBuilder1.CommitFeature()
throughCurvesBuilder1.Destroy()

'theSession.DeleteUndoMark(markId3, Nothing)
theSession.SetUndoMarkName(markId1, "Datum Plane")

Try
' Expression is still in use.
workPart.Expressions.Delete(expression1)
Catch ex As NXException
ex.AssertErrorCode(1050029)
End Try

End Sub

Function SelectAnObject(ByRef selObj As NXObject)
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim message As String = "Selection"
Dim title As String = "Select The Base Plane"
'Dim selectedObject As NXObject = Nothin
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
'Dim typeArray() As Selection.SelectionType ={Selection.SelectionType.All}
Dim typeArray As Selection.SelectionType =Selection.SelectionType.All
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(message, title,scope,False,typeArray,selObj,cursor)
' If resp = Selection.Response.ObjectSelected Or _
' resp = Selection.Response.ObjectSelectedByName Then
' Return Selection.Response.Ok
' Else
'Return Selection.Response.Cancel
' End If
End Function

Function SelectSurface(ByRef selObj As NXObject)
Dim theUI As UI = UI.GetUI
Dim cursor As Point3d
Dim message As String = "Selection"
Dim title As String = "Select The Surface"
'Dim selectedObject As NXObject = Nothin
Dim scope As Selection.SelectionScope = Selection.SelectionScope.AnyInAssembly
'Dim typeArray() As Selection.SelectionType ={Selection.SelectionType.All}
Dim typeArray As Selection.SelectionType =Selection.SelectionType.All
Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(message, title,scope,False,typeArray,selObj,cursor)
' If resp = Selection.Response.ObjectSelected Or _
' resp = Selection.Response.ObjectSelectedByName Then
' Return Selection.Response.Ok
' Else
'Return Selection.Response.Cancel
' End If
End Function

End Module

It doesn't look like the resulting section curves are being added to the through curve builder. You then get an error because no curves have been specified.