Cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted

Error at NX Open Builder.commit

Experimenter
Experimenter

I am using the following code in NX12 to automate spline generation and thru curves. I am calling point data from a text file and trying to generate the spline. But I am getting error at builder.commit. Could you please help me in this.

 

 

Option Strict Off
Imports System
Imports NXOpen

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

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim displayPart as Part = theSession.Parts.Display
Dim workPart as Part = theSession.Parts.Work
Dim ufs as UF.UFSession = UF.UFSession.GetUFSession()
dim studiospline as Features.StudioSplineBuilderEx
studiospline = workPart.Features.CreateStudioSplineBuilderEx(Nothing)
studiospline.IsAssociative = True
studiospline.InputCurveOption = Features.StudioSplineBuilderEx.InputCurveOptions.Hide
studiospline.Type = Features.StudioSplineBuilderEx.Types.ThroughPoints
studiospline.Degree = 3
studiospline.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
studiospline.IsPeriodic = False
dim knots1(-1) as double
studiospline.SetKnots(knots1)
dim parameters1(-1) as double
studiospline.SetParameters(parameters1)
dim nullDirection as Direction = Nothing
dim nullScalar as Scalar = Nothing
dim nulloffset as Offset = Nothing
dim lines as string() = System.IO.File.ReadAlllines("C:\Users\cimar\Desktop\New folder\spline_Automation - Copy.txt")
dim n as integer = lines.length
dim i as integer = 0
dim gcd(n) as Features.GeometricConstraintData
For each line as string in lines
gcd(i) = studiospline.ConstraintManager.CreateGeometricConstraintData()
dim coordinate as string() = line.Split(" ")
dim pt1(2) as double
dim x as double=system.Double.parse(coordinate(0))
dim y as double=system.Double.parse(coordinate(1))
dim z as double=system.Double.parse(coordinate(2))

pt1(0) = x
'Msgbox("x = " & x)
pt1(1) = y
'Msgbox("y = " & y)
pt1(2) = z
'Msgbox("z = " & z)

Dim coordinates1 As Point3d = New NXOpen.Point3d(x,y,z)
Dim point1 As NXOpen.Point
point1 = workPart.Points.CreatePoint(coordinates1)
gcd(i).Point = point1
studiospline.ConstraintManager.Append(gcd(i))
gcd(i).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
gcd(i).TangentDirection = nullDirection
gcd(i).TangentMagnitude = nullScalar
gcd(i).Curvature = nulloffset
gcd(i).CurvatureDerivative = nulloffset
gcd(i).HasSymmetricModelingConstraint = False
i = i+1
Next
studiospline.ConstraintManager.SetContents(gcd)
dim feature1 as Features.Feature
feature1 = studiospline.Commit()
workPart.modelingViews.workView.Fit()
feature1.SetName("SEC_" & i )
End sub
end module

screen_shot1.pngscreen_shot2.jpg

6 REPLIES 6

Re: Error at NX Open Builder.commit

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

"Error in external library. See system log for details."

 

What's the log file have to say? Don't post the entire log file here, it contains sensitive information in the header that you shouldn't post on a forum.

NX menu -> help -> log file

Re: Error at NX Open Builder.commit

Experimenter
Experimenter

Hello, @cowski1  

Thank You for the reply


Though i managed to overcome the error it wasn't solved totally but partially, iam able to create spline with studiospline syntax but it  creates as an object instead of Studiospline added it doesnt show up in Part Navigator, can't edit the spline, can't  delete it from the workspace. 

Iam attaching the code, point data file(in .txt format) & Log File( part where the error shows up) below could you probably look into where iam doing wrong ???

 

The code goes like this......

 

Option Strict Off
Imports System
Imports NXOpen

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

Try

Dim theSession As Session = Session.GetSession()
Dim theUI As UI = UI.GetUI()
Dim displayPart As Part = theSession.Parts.Display
Dim object0 As NXObject = Nothing
Dim workPart As Part = theSession.Parts.Work
Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()
Dim studiospline As Features.StudioSplineBuilderEx = Nothing
studiospline = workPart.Features.CreateStudioSplineBuilderEx(object0)
studiospline.IsAssociative = True
studiospline.InputCurveOption = Features.StudioSplineBuilderEx.InputCurveOptions.Hide
studiospline.Type = Features.StudioSplineBuilderEx.Types.ThroughPoints
studiospline.Degree = 3
studiospline.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
studiospline.IsPeriodic = False
Dim knots1(-1) As Double
studiospline.SetKnots(knots1)
Dim parameters1(-1) As Double
studiospline.SetParameters(parameters1)
Dim nullDirection As Direction = Nothing
Dim nullScalar As Scalar = Nothing
Dim nulloffset As Offset = Nothing
Dim lines As String() = System.IO.File.ReadAlllines("C:\Users\admin\Desktop\New_folder\spline_Automation - Copy.txt")
Dim n As Integer = lines.length
Dim i As Integer = 0
Dim gcd(n) As Features.GeometricConstraintData
For Each line As String In lines
gcd(i) = studiospline.ConstraintManager.CreateGeometricConstraintData()
Dim coordinate As String() = line.Split(" ")
Dim pt1(2) As Double
Dim x As Double = system.Double.parse(coordinate(0))
Dim y As Double = system.Double.parse(coordinate(1))
Dim z As Double = system.Double.parse(coordinate(2))

pt1(0) = x
'Msgbox("x = " & x)
pt1(1) = y
'Msgbox("y = " & y)
pt1(2) = z
'Msgbox("z = " & z)

Dim coordinates1 As Point3d = New NXOpen.Point3d(x, y, z)
Dim point1 As NXOpen.Point = Nothing
point1 = workPart.Points.CreatePoint(coordinates1)
gcd(i).Point = point1
studiospline.ConstraintManager.Append(gcd(i))
gcd(i).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
gcd(i).TangentDirection = nullDirection
gcd(i).TangentMagnitude = nullScalar
gcd(i).Curvature = nulloffset
gcd(i).CurvatureDerivative = nulloffset
gcd(i).HasSymmetricModelingConstraint = False
i = i + 1
Next
studiospline.ConstraintManager.SetContents(gcd)
Dim feature1 As NXOpen.Features.Feature = Nothing
feature1 = studiospline.Commit()
workPart.modelingViews.workView.Fit()
feature1.SetName("SEC_" & i)
studiospline.Destroy()

Catch e As NXException

End Try

End Sub
End Module

 

 

 

 

Re: Error at NX Open Builder.commit

Gears Esteemed Contributor Gears Esteemed Contributor
Gears Esteemed Contributor

Instead of using:

Dim n As Integer = lines.length

use:

Dim n As Integer = lines.GetUpperBound(0)

Creating a geometric constraints data array the size of the "length" of the lines array will result in one too many constraints in the array, which will remain empty and confuse the spline builder.

 

 

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()
    Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()
    Dim lw as ListingWindow = theSession.ListingWindow
    
    Sub Main(ByVal args() As String)
    
        lw.open
        Dim lines as String()
        Try
            lines = System.IO.File.ReadAlllines("C:\Users\admin\Desktop\New_folder\spline_Automation - Copy.txt")
        Catch e as Exception
            lw.writeline("Error: unable to read file")
            lw.writeline(e.ToString)
            lw.writeline("journal exiting")
            exit sub
        End Try

        Dim object0 As NXObject = Nothing
        Dim workPart As Part = theSession.Parts.Work
        Dim studiospline As Features.StudioSplineBuilderEx = Nothing
        studiospline = workPart.Features.CreateStudioSplineBuilderEx(object0)
        studiospline.IsAssociative = True
        studiospline.InputCurveOption = Features.StudioSplineBuilderEx.InputCurveOptions.Hide
        studiospline.Type = Features.StudioSplineBuilderEx.Types.ThroughPoints
        studiospline.Degree = 3
        studiospline.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
        studiospline.IsPeriodic = False
        Dim knots1(-1) As Double
        studiospline.SetKnots(knots1)
        Dim parameters1(-1) As Double
        studiospline.SetParameters(parameters1)
        Dim nullDirection As Direction = Nothing
        Dim nullScalar As Scalar = Nothing
        Dim nulloffset As Offset = Nothing
        Dim n As Integer = lines.GetUpperBound(0)
        Dim i As Integer = 0
        Dim gcd(n) As Features.GeometricConstraintData
        For Each line As String In lines
            gcd(i) = studiospline.ConstraintManager.CreateGeometricConstraintData()
            Dim coordinate As String() = line.Split("	")
            Dim pt1(2) As Double
            Dim x As Double = system.Double.parse(coordinate(0))
            Dim y As Double = system.Double.parse(coordinate(1))
            Dim z As Double = system.Double.parse(coordinate(2))
        
            pt1(0) = x
            'Msgbox("x = " & x)
            pt1(1) = y
            'Msgbox("y = " & y)
            pt1(2) = z
            'Msgbox("z = " & z)
        
            Dim coordinates1 As Point3d = New NXOpen.Point3d(x, y, z)
            Dim point1 As NXOpen.Point = Nothing
            point1 = workPart.Points.CreatePoint(coordinates1)
            gcd(i).Point = point1
            studiospline.ConstraintManager.Append(gcd(i))
            gcd(i).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
            gcd(i).TangentDirection = nullDirection
            gcd(i).TangentMagnitude = nullScalar
            gcd(i).Curvature = nulloffset
            gcd(i).CurvatureDerivative = nulloffset
            gcd(i).HasSymmetricModelingConstraint = False
            i = i + 1
        Next
        studiospline.ConstraintManager.SetContents(gcd)
        Dim feature1 As NXOpen.Features.Feature = Nothing
        feature1 = studiospline.Commit()
        workPart.modelingViews.workView.Fit()
        feature1.SetName("SEC_" & i)
        studiospline.Destroy()

    End Sub
End Module

Re: Error at NX Open Builder.commit

Experimenter
Experimenter

Hello, @cowski1 

Thank You for the reply 

 

using Upper Boundary instead of Length had solved that issue.

If im not asking much Could you look into the following code(a modification of previous code) 
Im trying for Surface Automation but it results in Error after spline creation stating as " System.NullReferenceException: Object reference not set to an instance of an object."

 

Please find the attachments below of log file & point files for added clarification

 

 

Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Utilities
Imports System.Windows.Forms
Imports NXOpen.UF

Module NXJournal
    Public workpart As Part
    Public ufs As UFSession
    Public c As Integer
    Dim theSession As Session = Session.GetSession()
    Dim theUI As UI = UI.GetUI()

    Dim lw As ListingWindow = theSession.ListingWindow


    Sub Main(ByVal args() As String)


        Dim files() As String = IO.Directory.GetFiles("C:\Users\admin\Desktop\New_folder")
        c = files.Length
        Dim SplineTag(c) As String
        Dim h As Integer = 1
        For Each file As String In files
            lw.open()
            Dim lines As String()
            Try
                lines = System.IO.File.ReadAlllines(file)
            Catch e As Exception
                lw.writeline("Error: unable to read file")
                lw.writeline(e.ToString)
                lw.writeline("journal exiting")
                Exit Sub
            End Try

            Dim object0 As NXObject = Nothing
            Dim workPart As Part = theSession.Parts.Work
            Dim studiospline As Features.StudioSplineBuilderEx = Nothing
            studiospline = workPart.Features.CreateStudioSplineBuilderEx(object0)
            studiospline.IsAssociative = True
            studiospline.InputCurveOption = Features.StudioSplineBuilderEx.InputCurveOptions.Hide
            studiospline.Type = Features.StudioSplineBuilderEx.Types.ThroughPoints
            studiospline.Degree = 3
            studiospline.MatchKnotsType = Features.StudioSplineBuilderEx.MatchKnotsTypes.None
            studiospline.IsPeriodic = False
            Dim knots1(-1) As Double
            studiospline.SetKnots(knots1)
            Dim parameters1(-1) As Double
            studiospline.SetParameters(parameters1)
            Dim nullDirection As Direction = Nothing
            Dim nullScalar As Scalar = Nothing
            Dim nulloffset As Offset = Nothing
            Dim n As Integer = lines.GetUpperBound(0)
            Dim i As Integer = 0
            Dim gcd(n) As Features.GeometricConstraintData
            For Each line As String In lines
                gcd(i) = studiospline.ConstraintManager.CreateGeometricConstraintData()
                Dim coordinate As String() = line.Split("	")
                Dim pt1(2) As Double
                Dim x As Double = system.Double.parse(coordinate(0))
                Dim y As Double = system.Double.parse(coordinate(1))
                Dim z As Double = system.Double.parse(coordinate(2))

                pt1(0) = x
                'Msgbox("x = " & x)
                pt1(1) = y
                'Msgbox("y = " & y)
                pt1(2) = z
                'Msgbox("z = " & z)

                Dim coordinates1 As Point3d = New NXOpen.Point3d(x, y, z)
                Dim point1 As NXOpen.Point = Nothing
                point1 = workPart.Points.CreatePoint(coordinates1)
                gcd(i).Point = point1
                studiospline.ConstraintManager.Append(gcd(i))
                gcd(i).AutomaticConstraintDirection = Features.GeometricConstraintData.ParameterDirection.Iso
                gcd(i).TangentDirection = nullDirection
                gcd(i).TangentMagnitude = nullScalar
                gcd(i).Curvature = nulloffset
                gcd(i).CurvatureDerivative = nulloffset
                gcd(i).HasSymmetricModelingConstraint = False
                i = i + 1
            Next
            studiospline.ConstraintManager.SetContents(gcd)
            Dim feature1 As NXOpen.Features.Feature = Nothing
            feature1 = studiospline.Commit()
            workPart.modelingViews.workView.Fit()
            feature1.SetName("SEC_" & h)
            SplineTag(h) = feature1.Tag
            studiospline.Destroy()
            h = h + 1
        Next
        ThroughCurves(c)

    End Sub

    Public Function ThroughCurves(ByVal c As Integer)

        Dim tcb As Features.ThroughCurvesBuilder
        Dim feature(0) As Features.Feature
        Dim sections() As Section
        Dim section_j As Section
        Dim studiospline As Features.StudioSpline
        Dim spline As Spline
        Dim splinetag_j As Tag
        Dim cftr As CurveFeatureTangentRule
        Dim rule(0) As SelectionIntentRule

        tcb = workPart.Features.CreateThroughCurvesBuilder(Nothing)
        tcb.PreserveShape = False
        tcb.Alignment.AlignCurve.DistanceTolerance = 0.01
        tcb.Alignment.AlignCurve.ChainingTolerance = 0.0095
        tcb.SectionTemplateString.DistanceTolerance = 0.01
        tcb.SectionTemplateString.ChainingTolerance = 0.0095
        tcb.Alignment.AlignCurve.AngleTolerance = 0.5
        tcb.SectionTemplateString.AngleTolerance = 0.5

        For j As Integer = 0 To c - 1
            section_j = workPart.Sections.CreateSection(0.00095, 0.01, 0.5)
            tcb.SectionsList.Append(section_j)
            splinetag_j = NXObjectManager.Get((SplineTag_j)).Tag
            studiospline = CType(NXObjectManager.Get(splinetag_j), Features.StudioSpline)
            feature(0) = studiospline
            spline = CType(studiospline.FindObject("CURVE 1"), Spline)
            cftr = workPart.ScRuleFactory.CreateRuleCurveFeatureTangent(feature, spline, Nothing, False, 0.0095, 0.5)
            section_j.AllowSelfIntersection(False)

            rule(0) = cftr
            Dim junk3(2) As Double
            Dim junk As Double
            Dim point(2) As Double
            Dim splineData As UFCurve.Spline = Nothing
            ufs.Modl.AskCurveProps(spline.Tag, splineData.start_Param, point, junk3, junk3, junk3, junk, junk)
            Dim hp As Point3d = New Point3d(point(0), point(1), point(2))
            section_j.AddToSection(rule, spline, Nothing, Nothing, hp, Section.mode.Create, False)
            'Redim Preserve sections(j)
            'sections(j) = section_j
        Next

        Dim ThroughCurvesOBJ As Features.ThroughCurves = tcb.CommitFeature()
        tcb.Destroy()
    End Function
End Module

Re: Error at NX Open Builder.commit

Legend
Legend

@Satya3 

The application threw cause you didn't initialize your workpart

 

Public workpart As Part = theSession.Parts.Work

and your ufsession

 

Public ufs As UFSession = UFSession.GetUFSession()

Addtionally your application will throw more errors because the variable 

splinetag_j

would be null at the time and can't be typecasted to StudioSpline.

I would suggest you to debug it. 

伊尔凡

Re: Error at NX Open Builder.commit

Experimenter
Experimenter

Hello  @Irfan23

Thank you for the interest

 

yes, you are right 
I had applied the changes that you suggested 
But still the error occurs at line no. 124

splinetag_j = NXObjectManager.Get((SplineTag_j)).Tag

Error message says : System.NullReferenceException: Object reference not set to an instance of an object.

Any suggestions on what/where im going wrong ..???