Get Curve from centerline2dBuilder

Hi, I'm wondering how I can get the 2D Centerline created by the centerline2dBuilder as a NXOpen.curve. Is this possible?
Thanks for any suggestions..

Dim nullNXOpen_Annotations_centerline2d As NXOpen.Annotations.centerline2d = Nothing
Dim centerline2dBuilder1 As NXOpen.Annotations.centerline2dBuilder
centerline2dBuilder1 = workPart.Annotations.Centerlines.Createcenterline2dBuilder(nullNXOpen_Annotations_centerline2d)
centerline2dBuilder1.Settings.Gap = 1.5
centerline2dBuilder1.Settings.Size = 3.0
centerline2dBuilder1.Settings.Extension = 5.0
centerline2dBuilder1.Settings.IndividualDistance = True
centerline2dBuilder1.Settings.Color = workPart.Colors.Find("Green")
centerline2dBuilder1.Settings.Width = NXOpen.Annotations.CenterlineSettingsBuilder.CenterlineThickness.Four
Dim point1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side1.SetValue(spline1, workPart.ModelingViews.WorkView, point1)
centerline2dBuilder1.AddExtension(1, 5.0)
Dim point2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side2.SetValue(spline2, workPart.ModelingViews.WorkView, point2)
Dim nXObject1 As NXOpen.NXObject
nXObject1 = centerline2dBuilder1.Commit()

The centerline2D is an annotation object that does not inherit from the curve class. This means that you cannot directly convert it to a curve object. However, you can get the "components" (individual pieces) of the annotation and create a line object from that information. The snippet below shows how to get the components and create a line object from that info.

Dim nXObject1 As NXOpen.Annotations.Centerline2d
nXObject1 = centerline2dBuilder1.Commit()

centerline2dBuilder1.Destroy()

'lw.WriteLine("nXObject1.GetType.ToString = " & nXObject1.GetType.ToString)
'lw.WriteLine("annotation origin: " & nXObject1.AnnotationOrigin.ToString)

Dim cd1 As Annotations.ComponentData = workPart.Annotations.CreateComponentData(nXObject1)
Dim lc1() As Annotations.LineComponent = cd1.GetLineComponents()

Dim sp As Point3d = lc1(0).StartPoint
Dim ep As Point3d = lc1(lc1.GetUpperBound(0)).EndPoint
lw.WriteLine("start point: " & sp.ToString)
lw.WriteLine("end point: " & ep.ToString)
Dim centerLine As Line = workPart.Curves.CreateLine(sp, ep)

Thanks for your help!
Which Information can I also get from the ".GetLineComponents"
of the Annotation? Is it possible to get some Points between, maybe at 25% or 50%? My "centerline2D" is the middle curve of 2 selected curves.

Here is my code so far:

Module NXJournal
Public ufs As UFSession = UFSession.GetUFSession()
Public theUI As UI = ui.GetUI
Public theSession As Session = Session.GetSession()
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Public markId1 As Session.UndoMarkId
Public title as String
Public selobj As NXObject
Public cursor As Point3d

Sub Main
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Start")

title="Select Curve 1"
If select_spline(selobj) = Selection.Response.Ok
spline1 = selobj
Else
Exit Sub
End If

title="Select Curve 2"
If select_spline(selobj) = Selection.Response.Ok
spline2 = selobj
Else
Exit Sub
End If

Dim lw As ListingWindow = theSession.ListingWindow
lw.Open()
Dim nullNXOpen_Annotations_centerline2d As NXOpen.Annotations.centerline2d = Nothing
Dim centerline2dBuilder1 As NXOpen.Annotations.centerline2dBuilder
centerline2dBuilder1 = workPart.Annotations.Centerlines.Createcenterline2dBuilder(nullNXOpen_Annotations_centerline2d)
centerline2dBuilder1.Settings.Gap = 1.5
centerline2dBuilder1.Settings.Size = 3.0
centerline2dBuilder1.Settings.Extension = 5.0
centerline2dBuilder1.Settings.IndividualDistance = True
centerline2dBuilder1.Settings.Color = workPart.Colors.Find("Green")
centerline2dBuilder1.Settings.Width = NXOpen.Annotations.CenterlineSettingsBuilder.CenterlineThickness.Four
Dim point1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side1.SetValue(spline1, workPart.ModelingViews.WorkView, point1)
centerline2dBuilder1.AddExtension(1, 5.0)
Dim point2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side2.SetValue(spline2, workPart.ModelingViews.WorkView, point2)
Dim nXObject1 As NXOpen.NXObject
nXObject1 = centerline2dBuilder1.Commit()
centerline2dBuilder1.Destroy()
'lw.WriteLine("nXObject1.GetType.ToString = " & nXObject1.GetType.ToString)
'lw.WriteLine("annotation origin: " & nXObject1.AnnotationOrigin.ToString)
Dim cd1 As Annotations.ComponentData = workPart.Annotations.CreateComponentData(nXObject1)
Dim lc1() As Annotations.LineComponent = cd1.GetLineComponents()
Dim sp As Point3d = lc1(0).StartPoint
Dim ep As Point3d = lc1(lc1.GetUpperBound(0)).EndPoint
For i=0 to lc1.GetUpperBound(0)
lw.WriteLine("i="&i)
next i
lw.WriteLine("start point: " & sp.ToString)
lw.WriteLine("end point: " & ep.ToString)
Dim centerLine As Line = workPart.Curves.CreateLine(sp, ep)

End Sub
Function select_spline(ByRef selobj As NXObject) As Selection.Response
Dim theUI As UI = ui.GetUI
Dim cursor As Point3d
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.Curves}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
"Select a spline", title, _
Selection.SelectionScope.AnyInAssembly, _
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

The centerline2D object has a .AnnotationOrigin property; in my limited testing, it appears to return the midpoint of the centerline.

The .GetLineComponents method will return a line component object for each individual segment of the centerline curve. You can get the start and end point for each individual segment (and not much else). My code above looks at the start point of the first segment and the end point of the last segment then creates a line object given those points. With this line curve, you could use one of the .CreatePoint methods to get a location anywhere along the curve.

Alternately, since you know the overall start and end point, you could use some basic algebra equations for a line and calculate any point on the line. This method would not require the creation of any additional objects (lines or points).

Below is now my code for the creation of a middle curve
with the centerline2D Feature. Thanks for your help!
The user is prompted to select 2 curves. Then the middle
curve is created.

Option Strict Off
Imports System
Imports System.IO
Imports NXOpen
Imports NXOpen.Features
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports System.Diagnostics
Imports System.Collections
Imports System.Maths
Imports System.Collections.Generic

Module NXJournal
Public ufs As UFSession = UFSession.GetUFSession()
Public theUI As UI = ui.GetUI
Public theSession As Session = Session.GetSession()
Public workPart As Part = theSession.Parts.Work
Public displayPart As Part = theSession.Parts.Display
Public markId1, markId2 As Session.UndoMarkId
'Hier alle öffentlichen Variablen mit Public x as .. deklarieren
Public title as String
Public perc as String
Public name as String
Public selobj As NXObject
Public cursor As Point3d
'---------------------
Public i as Integer = 0
Public pi as double = 3.141592654
Public curve1, curve2 As Curve
Public edge1, edge2 As Edge
Public ArrayOfPoints(-1) As Point
Public curveTag As NXOpen.Tag

Sub Main
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Studio Spline Thru Points")
title="Select Curve 1"
If select_EdgeOrCurve(selobj) = Selection.Response.Ok
If selobj.GetType.ToString ="NXOpen.Edge" Then
edge1=selobj
ufs.Modl.CreateCurveFromEdge(selobj.Tag, curveTag)
curve1 = Utilities.NXObjectManager.Get(curveTag)
call displayMod_curve(curve1, 30, 2, 2, True) 'Kurvenstyle ändern und blanken
Else
curve1 = selobj
call displayMod_curve(curve1, 36, 0, 0, False) 'Kurvenstyle ändern
End If
Else
Exit Sub
End If
title="Select Curve 2"
If select_EdgeOrCurve(selobj) = Selection.Response.Ok
If selobj.GetType.ToString ="NXOpen.Edge" Then
edge2=selobj
ufs.Modl.CreateCurveFromEdge(selobj.Tag, curveTag)
curve2 = Utilities.NXObjectManager.Get(curveTag)
call displayMod_curve(curve2, 30, 2, 2, True) 'Kurvenstyle ändern und blanken
Else
curve2 = selobj
call displayMod_curve(curve2, 36, 0, 0, False) 'Kurvenstyle ändern
End If
Else
Exit Sub
End If

Dim nullNXOpen_Annotations_centerline2d As NXOpen.Annotations.centerline2d = Nothing
Dim centerline2dBuilder1 As NXOpen.Annotations.centerline2dBuilder
centerline2dBuilder1 = workPart.Annotations.Centerlines.Createcenterline2dBuilder(nullNXOpen_Annotations_centerline2d)
centerline2dBuilder1.Settings.Gap = 1.5
centerline2dBuilder1.Settings.Size = 3.0
'centerline2dBuilder1.Settings.Extension = 5.0
centerline2dBuilder1.Settings.IndividualDistance = True
centerline2dBuilder1.Settings.Color = workPart.Colors.Find("Green")
centerline2dBuilder1.Settings.Width = NXOpen.Annotations.CenterlineSettingsBuilder.CenterlineThickness.Four
Dim point1 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side1.SetValue(curve1, workPart.ModelingViews.WorkView, point1)
'centerline2dBuilder1.AddExtension(1, 5.0)
Dim point2 As NXOpen.Point3d = New NXOpen.Point3d(0.0, 0.0, 0.0)
centerline2dBuilder1.Side2.SetValue(curve2, workPart.ModelingViews.WorkView, point2)
Dim nXObject1 As NXOpen.NXObject
nXObject1 = centerline2dBuilder1.Commit()
centerline2dBuilder1.Destroy()
Dim cd1 As Annotations.ComponentData = workPart.Annotations.CreateComponentData(nXObject1)
Dim lc1() As Annotations.LineComponent = cd1.GetLineComponents()
Dim objects1(0) As NXOpen.NXObject
objects1(0) = nXObject1
Dim nErrs1 As Integer
nErrs1 = theSession.UpdateManager.AddToDeleteList(objects1)
Dim notifyOnDelete2 As Boolean
notifyOnDelete2 = theSession.Preferences.Modeling.NotifyOnDelete
Dim nErrs2 As Integer
nErrs2 = theSession.UpdateManager.DoUpdate(markId2)
Dim sp As Point3d = lc1(0).StartPoint
Dim mp As Point3D
Dim ep As Point3d = lc1(lc1.GetUpperBound(0)).EndPoint
For i=0 to lc1.GetUpperBound(0)
ReDim Preserve ArrayOfPoints(i)
If i=0 Then
ArrayOfPoints(i) = theSession.Parts.Work.Points.CreatePoint(sp)
ElseIf i=lc1.GetUpperBound(0) Then
ArrayOfPoints(i) = theSession.Parts.Work.Points.CreatePoint(ep)
Else
mp = lc1(i).StartPoint
ArrayOfPoints(i) = theSession.Parts.Work.Points.CreatePoint(mp)
End If
Next i
CreateStudioSplineThruPoints(ArrayOfPoints, 3)
End Sub

Public Sub CreateStudioSplineThruPoints(ByRef points() As Point, ByVal degree3 As Integer)
Dim Pcount As Integer = points.Length - 1
Dim nullFeatures_StudioSpline As Features.StudioSpline = Nothing
Dim studioSplineBuilderex1 As Features.StudioSplineBuilderEx
studioSplineBuilderex1 = workPart.Features.CreateStudioSplineBuilderEx(nullFeatures_StudioSpline)
studioSplineBuilderex1.OrientExpress.ReferenceOption = GeometricUtilities.OrientXpressBuilder.Reference.ProgramDefined
studioSplineBuilderex1.Degree = degree3
studioSplineBuilderex1.OrientExpress.AxisOption = GeometricUtilities.OrientXpressBuilder.Axis.Passive
studioSplineBuilderex1.OrientExpress.PlaneOption = GeometricUtilities.OrientXpressBuilder.Plane.Passive
studioSplineBuilderex1.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
Dim knots1(-1) As Double
studioSplineBuilderex1.SetKnots(knots1)
Dim parameters1(-1) As Double
studioSplineBuilderex1.SetParameters(parameters1)
Dim nullDirection As Direction = Nothing
Dim nullScalar As Scalar = Nothing
Dim nullOffset As Offset = Nothing
Dim geometricConstraintData(Pcount) As Features.GeometricConstraintData
For ii As Integer = 0 To Pcount
geometricConstraintData(ii) = studioSplineBuilderex1.ConstraintManager.CreateGeometricConstraintData()
geometricConstraintData(ii).Point = points(ii)
geometricConstraintData(ii).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
geometricConstraintData(ii).AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.Tangent
geometricConstraintData(ii).TangentDirection = nullDirection
geometricConstraintData(ii).TangentMagnitude = nullScalar
geometricConstraintData(ii).Curvature = nullOffset
geometricConstraintData(ii).CurvatureDerivative = nullOffset
geometricConstraintData(ii).HasSymmetricModelingConstraint = False
Next ii
studioSplineBuilderex1.ConstraintManager.SetContents(geometricConstraintData)
Dim feature1 As Features.Feature
feature1 = studioSplineBuilderex1.CommitFeature()
curve1 = CType(feature1.FindObject("CURVE 1"), Curve)
studioSplineBuilderex1.Destroy()
call displayMod_curve(curve1, 30, 2, 2, False) 'Kurvenstyle ändern und blanken
End Sub

Sub displayMod_curve(ByVal curve1 As Curve, clr As Integer, font As Integer, width As Integer, blank As Boolean)
Dim displayModification As DisplayModification
displayModification = theSession.DisplayManager.NewDisplayModification()
displayModification.NewColor = clr
If font=0 Then
displayModification.NewFont = DisplayableObject.ObjectFont.Solid
ElseIf font=1 Then
displayModification.NewFont = DisplayableObject.ObjectFont.Dashed
ElseIf font=2 Then
displayModification.NewFont = DisplayableObject.ObjectFont.LongDashed
End If
If width=0 Then
displayModification.NewWidth = DisplayableObject.ObjectWidth.Thin
ElseIf width=1 Then
displayModification.NewWidth = DisplayableObject.ObjectWidth.Normal
ElseIf width=2 Then
displayModification.NewWidth = DisplayableObject.ObjectWidth.Thick
End If
Dim objects1(0) As DisplayableObject
objects1(0) = curve1
displayModification.Apply(objects1)
displayModification.Dispose()
If blank=True then theSession.DisplayManager.BlankObjects(objects1)
End Sub

Function select_EdgeOrCurve(ByRef selobj As NXObject) As Selection.Response
Dim typeArray() As Selection.SelectionType = _
{Selection.SelectionType.CurvesAndEdges}
Dim resp As Selection.Response = theUI.SelectionManager.SelectObject( _
"Select An Edge or Curve", title, _
Selection.SelectionScope.AnyInAssembly, _
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