Showing results for 
Search instead for 
Do you mean 

Create Studio Spline from Convergent Model Curves (NX11)

Curves created on a convergent model (section, projected) are degree 1 splines. The simple section shown has 334 poles. To directly create a fitted spline the current method is to create a degree 3 spline with knot point at each internal pole.  The resulting fitted spline has 1033 poles, 333 knots and 334 segments.

Below is a journal which uses the original poles as point input for a fitted spline. I have used a fairly loose tolerance so that the spline of the fitted spline has 17 poles. It is readily seen on image.




The journal then creates a studio spline using these poles and the fitted spline is removed.  The studio spline is ready edited so that its shape can be improved according to design requirements.  Of course the tolerance can be tightened.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.UF
Imports NXOpen.Features
Module StudioSplineFromConvergentSplines
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim lw As ListingWindow = s.ListingWindow
    Dim wp As Part = s.Parts.Work
    Sub Main()
        ' select a convergent body section curve spline
        Dim prompt As String = "Select convergent section spline"
        Dim selobj As TaggedObject = Nothing
        Dim splineobj As Spline = Nothing
        Dim splineorder As Integer = Nothing
        Dim resp1 As Selection.Response = Selection.Response.Cancel
        Dim markId1 As NXOpen.Session.UndoMarkId = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Undo0")
        While select_a_spline(prompt, selobj) = 5
            If selobj.ToString.Contains("Spline") Then
                splineobj = CType(selobj, Spline)
                ' check spline degree.  Must be 1 for convergent model section spline
                splineorder = splineobj.Order
                If splineorder <> 2 Then
                    GoTo restart1
                End If
            End If
        End While
    End Sub
    Private Function select_a_spline(ByVal prompt As String, ByRef selobj As TaggedObject) As Selection.Response
        Dim cursor As Point3d = Nothing
        Dim mask(0) As Selection.MaskTriple
        mask(0).Type = UFConstants.UF_spline_type
        mask(0).Subtype = 0
        mask(0).SolidBodySubtype = 0
        Dim resp As Selection.Response = _
     ui.SelectionManager.SelectTaggedObject(prompt, prompt, _
         Selection.SelectionScope.AnyInAssembly, _
         Selection.SelectionAction.ClearAndEnableSpecific, _
         False, False, mask, selobj, cursor)
        Return resp
    End Function
    Public Sub CreateSectionStudioSpline1(ByVal spline1 As Spline)
        Dim splinepoles() As Point3d = spline1.Get3DPoles
        Dim splineparms(splinepoles.Length - 1) As Double
        Dim fitspline1 As Feature = Nothing
        Dim points1(splinepoles.Length - 1) As Point
        For i As Integer = 0 To splinepoles.Length - 1
            points1(i) = wp.Points.CreatePoint(splinepoles(i))
        Dim pntgroup As Group = Nothing
        CreateGroupPoints(points1, pntgroup)
        CreateFittedSplineDegreeTolerance(spline1, pntgroup, points1, fitspline1)
        Dim newspline1 As Spline = Nothing
        Dim objects1() As NXObject = fitspline1.GetEntities
        If objects1(0).ToString.Contains("Spline") Then
            newspline1 = DirectCast(objects1(0), Spline)
        End If
    End Sub

    Public Sub CreateGroupPoints(ByVal points() As Point, ByRef pntgrp As Group)
        Dim nullNXOpen_Group As NXOpen.Group = Nothing
        Dim groupBuilder1 As NXOpen.GroupBuilder = Nothing
        groupBuilder1 = wp.CreateGatewayGroupBuilder(nullNXOpen_Group)
        groupBuilder1.ActivegroupOption = True
        groupBuilder1.ActionType = 0
        groupBuilder1.GroupDisplayProperties = False
        groupBuilder1.GroupName = "TEMP_GROUP"
        Dim added1 As Boolean = Nothing
        For i As Integer = 0 To points.Length - 1
            added1 = groupBuilder1.ObjectsInGroup.Add(points(i))
        Dim nXObject1 As NXOpen.NXObject = Nothing
        pntgrp = groupBuilder1.Commit()
    End Sub
    Private Sub CreateFittedSplineDegreeTolerance(ByVal spline1 As Spline, ByVal group1 As Group, ByVal points() As Point, _
                                                  ByRef fitspline1 As Feature)
        Dim partunits As Integer = Nothing
        ufs.Part.AskUnits(wp.Tag, partunits)
        Dim tol1 As Double = Nothing
        If partunits = UFConstants.UF_PART_METRIC Then
            tol1 = 0.5
            tol1 = 0.125
        End If
        Dim splineperiodic As Boolean = spline1.Periodic
        Dim nullNXOpen_Features_FitCurve As NXOpen.Features.FitCurve = Nothing
        Dim fitCurveBuilder1 As NXOpen.Features.FitCurveBuilder = Nothing
        fitCurveBuilder1 = wp.Features.CreateFitCurveBuilder(nullNXOpen_Features_FitCurve)
        fitCurveBuilder1.ProjectionDirectionOption = NXOpen.Features.FitCurveBuilder.ProjectionDirectionOptions.Normal
        fitCurveBuilder1.IsClosedCurve = splineperiodic
        fitCurveBuilder1.FittingParameters = NXOpen.Features.FitCurveBuilder.FittingParametersOptions.DegreeAndTolerance
        fitCurveBuilder1.Degree = 5
        fitCurveBuilder1.Tolerance = tol1
        fitCurveBuilder1.TargetSourceType = NXOpen.Features.FitCurveBuilder.TargetSourceTypes.SpecifiedPoints
        Dim objects(points.Length) As NXOpen.TaggedObject
        For i As Integer = 0 To points.Length - 1
            objects(i) = points(i)
        objects(points.Length) = group1
        Dim added1 As Boolean = Nothing
        added1 = fitCurveBuilder1.Target.Add(objects)
        fitspline1 = fitCurveBuilder1.CommitFeature()
    End Sub
    Private Sub ReplaceFittedSplineWithStudioSpline(ByVal spline1 As Spline)
        Dim markId1 As NXOpen.Session.UndoMarkId = s.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Undo1")
        Dim removeParametersBuilder1 As NXOpen.Features.RemoveParametersBuilder = Nothing
        removeParametersBuilder1 = wp.Features.CreateRemoveParametersBuilder()
        Dim added1 As Boolean = removeParametersBuilder1.Objects.Add(spline1)
        Dim nXObject1 As NXOpen.NXObject = removeParametersBuilder1.Commit()
        ' get spline data to create a studio spline
        Dim splineorder As Integer = spline1.Order
        Dim splineperiod As Boolean = spline1.Periodic
        Dim poles3d() As Point3d = spline1.Get3DPoles
        ' create studio spline
        CreateStudioSplinebyPoles(poles3d, splineorder, splineperiod)
        ' delete the fit curve spline
        Dim objects2() As NXOpen.NXObject = {spline1}
        Dim nErrs2 As Integer = s.UpdateManager.DoUpdate(markId1)
    End Sub

    Private Sub CreateStudioSplinebyPoles(ByVal poles3d() As Point3d, ByVal splineorder As Integer, ByVal splineperiod As Boolean)
        Dim Pcount As Integer = poles3d.Length - 1
        Dim points(Pcount) As Point
        For i As Integer = 0 To Pcount
            points(i) = wp.Points.CreatePoint(poles3d(i))
        Dim nullNXObject As NXObject = Nothing
        Dim studioSplineBuilder1 As Features.StudioSplineBuilderEx
        studioSplineBuilder1 = wp.Features.CreateStudioSplineBuilderEx(nullNXObject)
        studioSplineBuilder1.Degree = splineorder - 1
        studioSplineBuilder1.IsPeriodic = splineperiod
        studioSplineBuilder1.Type = NXOpen.Features.StudioSplineBuilderEx.Types.ByPoles
        Dim constraints1(Pcount) As Features.GeometricConstraintData
        For i As Integer = 0 To Pcount
            Dim geometricConstraintData1 As Features.GeometricConstraintData
            geometricConstraintData1 = studioSplineBuilder1.ConstraintManager.CreateGeometricConstraintData()
            geometricConstraintData1.Point = points(i)
            geometricConstraintData1.AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
            geometricConstraintData1.AutomaticConstraintType = Features.GeometricConstraintData.AutoConstraintType.None
            Dim nullDirection As Direction = Nothing
            geometricConstraintData1.TangentDirection = nullDirection
            Dim nullScalar As Scalar = Nothing
            geometricConstraintData1.TangentMagnitude = nullScalar
            Dim nullOffset As Offset = Nothing
            geometricConstraintData1.Curvature = nullOffset
            geometricConstraintData1.CurvatureDerivative = nullOffset
            geometricConstraintData1.HasSymmetricModelingConstraint = False
            constraints1(i) = geometricConstraintData1
        Dim splineFeature As NXOpen.Features.StudioSpline = studioSplineBuilder1.Commit()
    End Sub
    Private Sub RemoveTemporaryGroup(ByVal pntgroup As Group)
        Dim nullNXOpen_Group As NXOpen.Group = Nothing
        Dim groupBuilder1 As NXOpen.GroupBuilder = Nothing
        groupBuilder1 = wp.CreateGatewayGroupBuilder(nullNXOpen_Group)
        groupBuilder1.ActivegroupOption = True
        groupBuilder1.ActionType = 3
        groupBuilder1.GroupInAction.Value = pntgroup
        Dim nXObject1 As NXOpen.NXObject = Nothing
        nXObject1 = groupBuilder1.Commit()
    End Sub
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module


Frank Swinkels


Re: Create Studio Spline from Convergent Model Curves (NX11)

[ Edited ]

I have created two further programs.


The first of these is to select a section of a degree 1 spline and create a single segment degree 5 studio spline.  The sections are then connected with G2 as shown below.




The second program allows me to select separate sections and create the studio spline to span across the regions to ignore as shown in the image below.


















Frank Swinkels