×
INTELLIGENT WORK FORUMS
FOR ENGINEERING PROFESSIONALS

Log In

Come Join Us!

Are you an
Engineering professional?
Join Eng-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Eng-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

NX VB Journal - Creating Spline using PtSlopeCrvatr Container

NX VB Journal - Creating Spline using PtSlopeCrvatr Container

NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
Hi,

This is related to the askfacedata/askfaceprops code I am working on but it is a separate question - so I figured I post it on its own.

I am trying to create a spline ultimately using CreateSplineThruPts but first I need to populate the PtSlopeCrvatr with data.  I have declared my variable as:

CODE

dim PTDATA() as NXOpen.UF.UFCurve.PtSlopeCrvatr = New NXOpen.UF.UFCurve.PtSlopeCrvatr() {}

But I still get "Object reference is not set to instance of object" as soon as I try to assign as follows:

CODE

for p as integer = 0 to totalpoints
PTDATA(p).point(0)=ptx
...etc...

How do I initialize the variable properly to be able to put data into it?

Thanks,
Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

If you don't know the size of the array you will need at the time of initialization, don't use the New constructor. Just dimension an empty array and ReDim it later when the needed size is known.

CODE

Dim ptx(2) As Double  
Dim total As Integer  

total = 3  

ptx(0) = 0  
ptx(1) = 1  
ptx(2) = 2  

Dim PTDATA() as NXOpen.UF.UFCurve.PtSlopeCrvatr  
ReDim PTDATA(total)  

For p As Integer = 0 to total  
  PTDATA(p).point = ptx  
Next  

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
I tried that too, even with the construction you suggest (No "New" and a redim later on) and I still get the same error.  I think for some reason NX doesn't "like" me referring to the PtSlopeCrvatr item while it is empty - which doesn't make sense to me because it needs to be empty so I can fill it :)

Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

I tested the code posted above and got no errors.

Which line of your code reports an error, and what does that line look like?

Also, note the difference above

CODE

PTDATA(p).point(0)=ptx

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
That difference was the difference (and the line with point(0) was where the error was reported).  Now I know I can't call out the points individually.  That works!

Thanks,
Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

Here's a quick example:

CODE

Option Strict Off  
Imports System  
Imports NXOpen  

Module NXJournal  
Sub Main  

Dim theSession As Session = Session.GetSession()  
Dim workPart As Part = theSession.Parts.Work  
Dim displayPart As Part = theSession.Parts.Display  
Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()  

dim myTag as Tag                      'tag for the new spline to be created
dim mySpline as Spline = nothing      'object variable for new spline
dim degree as integer = 3              'degree of spline created
dim periodicity as integer = 0          '0 for non-periodic, 1 for periodic (closed) spline
dim numPoints as integer = 4          'number of points passed to the CreateSplineThruPts method

'declare and populate point data
dim pt0(2) as double  
dim pt1(2) as double  
dim pt2(2) as double  
dim pt3(2) as double  

pt0(0) = 0  
pt0(1) = 2  
pt0(2) = 0  

pt1(0) = 2  
pt1(1) = 1  
pt1(2) = 0  

pt2(0) = 4  
pt2(1) = 3  
pt2(2) = 0  

pt3(0) = 6  
pt3(1) = 0  
pt3(2) = 0  

dim ptdata() as NXOpen.UF.UFCurve.PtSlopeCrvatr  
redim ptdata(3)  

ptdata(0).point = pt0  
ptdata(0).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO  
ptdata(0).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

ptdata(1).point = pt1  
ptdata(1).slope_type = UF.UFConstants.UF_CURVE_SLOPE_NONE  
ptdata(1).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

ptdata(2).point = pt2  
ptdata(2).slope_type = UF.UFConstants.UF_CURVE_SLOPE_NONE  
ptdata(2).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

ptdata(3).point = pt3  
ptdata(3).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO  
ptdata(3).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

'ufs.Curve.CreateSplineThruPts(degree, periodicity, numPoints, ptdata, _
' user specified parameterization of input points: use 'nothing' for default parameterization, _
' save defining data? 1 = yes (anything else = no) , return tag variable of new spline)

ufs.Curve.CreateSplineThruPts(degree, periodicity, numPoints, ptdata, nothing, 0, myTag)  

'convert Tag reference to NXOpen object
mySpline = Utilities.NXObjectManager.Get(myTag)  
'prove that the above line worked
msgbox("Length of spline: " & mySpline.GetLength)  

End Sub  
End Module  
 

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
Thanks cowski!

Now I understand the spline construction.  Still working on the overall picture.  More posts to come ;)

Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
Okay. it seems as though I keep missing something fundamental, but I can't see what it is.  I can get your code to work with explicit points, but when I run those points (generated from other code) it doesn't work.

The problem is I am assigning the .point data in a For-Next Loop and it reports everything ok, but as soon as I exit the loop it only remembers the last value.

CODE

for p as integer = 0 to kk-1
    pointdouble(0)=cpoint(p).coordinates.X
    pointdouble(1)=cpoint(p).coordinates.Y
    pointdouble(2)=cpoint(p).coordinates.Z

    point_data1(p).point = pointdouble
    point_data1(p).slope_type = UFConstants.UF_CURVE_SLOPE_NONE
    point_data1(p).crvatr_type = UFConstants.UF_CURVE_CRVATR_NONE
    
    lw.writeline("K= " & p.tostring &": " &point_data1(p).point(0) &","&point_data1(p).point(1) &","&point_data1(p).point(2))
next p

for p as integer = 0 to kk-1
    lw.writeline("K= " & p.tostring &": " &point_data1(p).point(0) &","&point_data1(p).point(1) &","&point_data1(p).point(2))
next

Gives me:
K= 0: 80.0068723329663,0.000311697607848771,25.0000086444894
K= 1: 82.6184557205712,0.0890023374493865,25.0002787371683
K= 2: 85.3356535714023,0.362087419874367,24.9997263024703
K= 3: 88.0324414244833,0.840184094211939,25.0008079122174
K= 4: 90.6374012069239,1.52693367761155,25.0014357866076
K= 5: 93.0355329341884,2.41816831811692,24.9993864675541
K= 6: 95.1594576479436,3.48239559087328,24.9988022552044
K= 7: 96.9428619602756,4.68411422968257,25.0003322542663
K= 8: 98.3237291689222,5.98321234054376,24.9988888939346
K= 9: 99.2751578945642,7.33331493597748,25.0002114846827
K= 10: 99.8265572327264,8.68491999661199,24.9998931806953
K= 11: 100,10,25
K= 0: 100,10,25
K= 1: 100,10,25
K= 2: 100,10,25
K= 3: 100,10,25
K= 4: 100,10,25
K= 5: 100,10,25
K= 6: 100,10,25
K= 7: 100,10,25
K= 8: 100,10,25
K= 9: 100,10,25
K= 10: 100,10,25
K= 11: 100,10,25

So as soon as I exit the loop my point values are "lost".  This is probably something VB related which I don't understand, and I guess I'm sorely lacking in VB training.

Thanks (again),
Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

I tried to reproduce your error in my code, but was unable to.

Boil your code down to a small journal that exhibits the error and we'll step through the whole thing.

For what it's worth, here's my test code:

CODE


Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

 '  Explicit Activation
 '      This entry point is used to activate the application explicitly
    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim displayPart As Part = theSession.Parts.Display  
        Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()  
        Dim lw As ListingWindow = theSession.ListingWindow  

Dim myTag As Tag  'tag for the new spline to be created
Dim mySpline As Spline = Nothing  'object variable for new spline
Dim degree As Integer = 3  'degree of spline created
Dim periodicity As Integer = 0  '0 for non-periodic, 1 for periodic (closed) spline
Dim numPoints As Integer = 4  'number of points passed to the CreateSplineThruPts method

 'declare and populate point data
        Dim pt0(2) As Double  
        Dim pt1(2) As Double  
        Dim pt2(2) As Double  
        Dim pt3(2) As Double  

        pt0(0) = 0  
        pt0(1) = 2  
        pt0(2) = 0  

        pt1(0) = 2  
        pt1(1) = 1  
        pt1(2) = 0  

        pt2(0) = 4  
        pt2(1) = 3  
        pt2(2) = 0  

        pt3(0) = 6  
        pt3(1) = 0  
        pt3(2) = 0  

        Dim ptdata() As NXOpen.UF.UFCurve.PtSlopeCrvatr  
        ReDim ptdata(3)  

        ptdata(0).point = pt0  
        ptdata(0).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO  
        ptdata(0).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

        ptdata(1).point = pt1  
        ptdata(1).slope_type = UF.UFConstants.UF_CURVE_SLOPE_NONE  
        ptdata(1).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

        ptdata(2).point = pt2  
        ptdata(2).slope_type = UF.UFConstants.UF_CURVE_SLOPE_NONE  
        ptdata(2).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

        ptdata(3).point = pt3  
        ptdata(3).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO  
        ptdata(3).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  

 'ufs.Curve.CreateSplineThruPts(degree, periodicity, numPoints, ptdata, _
 ' user specified parameterization of input points: use 'nothing' for default parameterization, _
 ' save defining data? 1 = yes (anything else = no) , return tag variable of new spline)

        ufs.Curve.CreateSplineThruPts(degree, periodicity, numPoints, ptdata, Nothing, 0, myTag)  

 'convert Tag reference to NXOpen object
        mySpline = Utilities.NXObjectManager.Get(myTag)  
 'prove that the above line worked
        MsgBox("Length of spline: " & mySpline.GetLength)  

        lw.Open()  
        For i As Integer = 0 To 3  
            lw.WriteLine(ptdata(i).point(0))  
            lw.WriteLine(ptdata(i).point(1))  
            lw.WriteLine(ptdata(i).point(2))  
            lw.WriteLine("")  
        Next  

    End Sub  


    Public Function GetUnloadOption(ByVal dummy As String) As Integer  

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

    End Function  

End Module  
 

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

How have you dimensioned the point_data() array?

Can you post that line(s) of code?

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
Here's my point_data1 declarations:

CODE

dim point_data1() as NXOpen.UF.UFCurve.PtSlopeCrvatr
...figure out value kk...
redim point_data1(kk-1)

I'll see if I can isolate a small working (or not) part of code that can be reproduced.

It's a question of assigning the .point values in the for-next loop.

Thanks,
Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

It is some years since I used the ufunc UF_CURVE_create_spline_thru_pts in c programs.  What I do remember is that when the number of points was more than a certain number (I don't remember the actual number) I had to allocate memory for the spline data. Note that the documentation makes no reference to this.

In the data that was written out I note that at k = 11 the data written out is the only data that is saved.

I think the wrapper method does  not allocate space correctly.

I have two suggestions.  One is to reduce the number of spline points and write out the data to test my theory.  If this is proven then this wrapper method is of little use to you therefore my second suggestion is to use the spline class.  If rquired I can make an example journal available.

Frank Swinkels

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

Jeff,

I modified my code to use loops similar to yours and saw the same problem. I think the problem is because objects (the ptdata object in our case) are reference types. This means they act like pointers; so when we loop through and change the data in pointdouble(), the object points to the new data rather than copying it into a separate variable.

One possible workaround would be to hold your point data in an array of arrays so that you have a separate copy of each point. This method is demonstrated below:

CODE


Option Strict Off  
Imports System  
Imports NXOpen  

Module Module1  

 '  Explicit Activation
 '      This entry point is used to activate the application explicitly
    Sub Main()  

        Dim theSession As Session = Session.GetSession()  
        Dim workPart As Part = theSession.Parts.Work  
        Dim displayPart As Part = theSession.Parts.Display  
        Dim ufs As UF.UFSession = UF.UFSession.GetUFSession()  
        Dim lw As ListingWindow = theSession.ListingWindow  

Dim myTag As Tag  'tag for the new spline to be created
Dim mySpline As Spline = Nothing  'object variable for new spline
Dim degree As Integer = 3  'degree of spline created
Dim periodicity As Integer = 0  '0 for non-periodic, 1 for periodic (closed) spline
Dim numPoints As Integer = 4  'number of points passed to the CreateSplineThruPts method

        Dim rand1 As New Random  
        Dim myPoints()() As Double = New Double(numPoints - 1)() {}  

 'declare and populate point data
        Dim pt0(2) As Double  

        lw.Open()  

        For i As Integer = 0 To numPoints - 1  
            myPoints(i) = New Double(2) {}  
            For j As Integer = 0 To 2  
                myPoints(i)(j) = rand1.Next(-10, 10)  
                lw.WriteLine(myPoints(i)(j))  
            Next  
            lw.WriteLine("")  
        Next  

        Dim ptdata() As NXOpen.UF.UFCurve.PtSlopeCrvatr  
        ReDim ptdata(numPoints - 1)  

        For i As Integer = 0 To numPoints - 1  
            ptdata(i).point = myPoints(i)  
            ptdata(i).slope_type = UF.UFConstants.UF_CURVE_SLOPE_NONE  
            ptdata(i).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE  
            lw.WriteLine(ptdata(i).point(0) & ", " & ptdata(i).point(1) & ", " & ptdata(i).point(2))  
        Next  

    End Sub  

    Public Function GetUnloadOption(ByVal dummy As String) As Integer  

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

    End Function  

End Module  

I don't bother to create the spline in this journal since the data is random. It might make for some interesting looking, but useless splines. The code above uses only 4 points, but I have tested with up to 50 points and all was well.

www.nxjournaling.com

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

(OP)
Thanks for all your input.  I moved the declaration of "pointdouble" inside the for-next loop and everything seems to work now.

Jeff

RE: NX VB Journal - Creating Spline using PtSlopeCrvatr Container

Excellent, even easier!

www.nxjournaling.com

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Eng-Tips Forums free from inappropriate posts.
The Eng-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Eng-Tips forums is a member-only feature.

Click Here to join Eng-Tips and talk with other members!


Resources