cancel
Showing results for 
Search instead for 
Did you mean: 

report possible bug

Creator
Creator

For the nxopen in C#,  from the fitting curve builder you can not get the curve generated. Getcommitedobject returns null.

6 REPLIES

Re: report possible bug

Siemens Phenom Siemens Phenom
Siemens Phenom

This is not a bug. A FitCurve is a Feature, not a NXObject (which is what Commit() /  GetCommittedObjects() returns).

 

Try using the CommitFeature() / GetFeature() methods.

Re: report possible bug

Creator
Creator

I has no problem to get the FitCurve feature.

But i cannot get the curve generated with from the fitcurve feature.

fitcurve.getentities() returns null.

Re: report possible bug

Phenom
Phenom

The .GetEntities method seems to work for me when creating an associative fit curve feature.

 

The following code is in VB, but it is pretty straightforward.

 

Option Strict Off
Imports System
Imports NXOpen

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "fit line"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim rnd1 As New Random
        Dim limit As Integer
        If workPart.PartUnits = BasePart.Units.Inches Then
            limit = 5
        Else
            limit = 130
        End If

        'create 3 random points
        Dim pt1 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt1.SetVisibility(SmartObject.VisibilityOption.Visible)
        Dim pt2 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt2.SetVisibility(SmartObject.VisibilityOption.Visible)
        Dim pt3 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt3.SetVisibility(SmartObject.VisibilityOption.Visible)



        Dim nullFeatures_FitCurve As Features.FitCurve = Nothing

        Dim fitCurveBuilder1 As Features.FitCurveBuilder
        fitCurveBuilder1 = workPart.Features.CreateFitCurveBuilder(nullFeatures_FitCurve)

        fitCurveBuilder1.Type = Features.FitCurveBuilder.Types.FitLine

        fitCurveBuilder1.ProjectionDirectionOption = Features.FitCurveBuilder.ProjectionDirectionOptions.Normal

        Dim added1 As Boolean
        added1 = fitCurveBuilder1.Target.Add(pt1)

        Dim added2 As Boolean
        added2 = fitCurveBuilder1.Target.Add(pt2)

        Dim added3 As Boolean
        added3 = fitCurveBuilder1.Target.Add(pt3)

        Dim nXObject1 As Features.FitCurve
        nXObject1 = fitCurveBuilder1.Commit()

        fitCurveBuilder1.Destroy()


        Dim theCurves() As NXObject = nXObject1.GetEntities
        lw.WriteFullline("number of curves: " & theCurves.Length.ToString)

        Dim theFitCurve As Line = theCurves(0)
        lw.WriteFullline("curve length: " & theFitCurve.GetLength.ToString)
        lw.WriteFullline("start point: " & theFitCurve.StartPoint.ToString)
        lw.WriteFullline("end point: " & theFitCurve.EndPoint.ToString)

        lw.Close()

    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

 

If you are creating an unassociative fit curve, there are work-arounds to get the resulting curve: examine the curve collection for the newest curve or initially create the fit curve as associative, grab the resulting curve then remove the feature parameters.

Re: report possible bug

Creator
Creator

Many thanks.

That is really strange. I just copy  your code and run it from the "journal-run".

Still i get the error saying that the getentities returns null.

 

 

 

 

.vb.jpgvb2.png

Re: report possible bug

Phenom
Phenom

I tested @cowski's code and it didn't work for me either.

After looking at some examples in the solution centre it looks like there was a bug with this until NX9.0.2. Not sure what version you are using though. Anyway, see this post: PR 6999929 for details.

I hacked coski1's test code to use the mentioned workaround and this works for me at NX8.5:

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

Module Module1

    Sub Main()

        Dim theSession As Session = Session.GetSession()
        Dim ufs As UFSession = UFSession.GetUFSession()
        If IsNothing(theSession.Parts.BaseWork) Then
            'active part required
            Return
        End If

        Dim workPart As Part = theSession.Parts.Work
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()

        Const undoMarkName As String = "fit line"
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, undoMarkName)

        Dim rnd1 As New Random
        Dim limit As Integer
        If workPart.PartUnits = BasePart.Units.Inches Then
            limit = 5
        Else
            limit = 130
        End If

        'create 3 random points
        Dim pt1 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt1.SetVisibility(SmartObject.VisibilityOption.Visible)
        Dim pt2 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt2.SetVisibility(SmartObject.VisibilityOption.Visible)
        Dim pt3 As Point = workPart.Points.CreatePoint(New Point3d(rnd1.Next(-limit, limit), rnd1.Next(-limit, limit), 0))
        pt3.SetVisibility(SmartObject.VisibilityOption.Visible)



        Dim nullFeatures_FitCurve As Features.FitCurve = Nothing

        Dim fitCurveBuilder1 As Features.FitCurveBuilder
        fitCurveBuilder1 = workPart.Features.CreateFitCurveBuilder(nullFeatures_FitCurve)

        fitCurveBuilder1.Type = Features.FitCurveBuilder.Types.FitLine

        fitCurveBuilder1.ProjectionDirectionOption = Features.FitCurveBuilder.ProjectionDirectionOptions.Normal

        Dim added1 As Boolean
        added1 = fitCurveBuilder1.Target.Add(pt1)

        Dim added2 As Boolean
        added2 = fitCurveBuilder1.Target.Add(pt2)

        Dim added3 As Boolean
        added3 = fitCurveBuilder1.Target.Add(pt3)

        Dim nXObject1 As Features.FitCurve
        Dim featTag As Tag
        ufs.Modl.AskCurrentFeature(workPart.tag,featTag)
				nXObject1 = DirectCast(NXOpen.Utilities.NXObjectManager.Get(featTag), NXOpen.Features.FitCurve)

        fitCurveBuilder1.Destroy()

        Dim theCurves() As NXObject = nXObject1.GetEntities
        lw.WriteFullline("number of curves: " & theCurves.Length.ToString)

        Dim theFitCurve As Line = theCurves(0)
        lw.WriteFullline("curve length: " & theFitCurve.GetLength.ToString)
        lw.WriteFullline("start point: " & theFitCurve.StartPoint.ToString)
        lw.WriteFullline("end point: " & theFitCurve.EndPoint.ToString)

        lw.Close()
	  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
Graham Inchley Snr R&D Engineer (Systems Development), Sandvik Coromant
Lenovo ThinkPad W540, Win7, 16GB. Developing in: Java | C | C# | KF
Production: NX8.5.3.3 MP11 64bit Testing: NX9.0.2.5

Re: report possible bug

Creator
Creator

 

I am using NX 9.0.0.

The workaround method works for me too.

Thank you.