×
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

ufs.curve.createSplineThruPts not being displayed

ufs.curve.createSplineThruPts not being displayed

ufs.curve.createSplineThruPts not being displayed

(OP)
Ive created a function that creates a spline based on subject.

I can't get the spline to appear in the cad window. What am i missing?

RE: ufs.curve.createSplineThruPts not being displayed

> What am i missing?

You're missing the explanation of your code that will allow people here to see the problems. Show us your code and then (maybe) someone can tell you what you're doing wrong.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)

CODE --> vb

Public Function makeSpline(ByVal points As ArrayList) As Spline

        Dim ufs As UF.UFSession = UF.UFSession.GetUFSession
        Dim mytag As Tag
        Dim mySpline As Spline = Nothing
        Dim degree As Integer = 3
        Dim periodicity As Integer = 0

        Dim numPoints As Integer = points.Count

        Dim pts As New ArrayList
        Dim pt(2) As Double

        For Each iPoint As Point3d In points
            pt(0) = iPoint.X
            pt(1) = iPoint.Y
            pt(2) = iPoint.Z
            Console.WriteLine("Point(" & pt(0).ToString() & "," & pt(1).ToString() & "," & pt(2).ToString() & ")")
            pts.Add(pt)
        Next

        Dim ptData(pts.Count - 1) As NXOpen.UF.UFCurve.PtSlopeCrvatr

        For i As Integer = 0 To pts.Count - 1
            ptData(i).point = pts(i)
            ptData(i).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO
            ptData(i).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE
        Next

        '  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)
        mySpline.SetVisibility(SmartObject.VisibilityOption.Visible)
        mySpline.RedisplayObject()
        MsgBox("Length of Spline = " & mySpline.GetLength)

        Return mySpline

    End Function 

RE: ufs.curve.createSplineThruPts not being displayed

Try adding something like this:

thesession.Parts.Work.ModelingViews.WorkView.Regenerate()

Mark Benson
Aerodynamic Model Designer

To a Designer, the glass was right on CAD.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
The spline length is coming out zero.

RE: ufs.curve.createSplineThruPts not being displayed

The point information in the ptData structure is being assigned incorrectly. It is expecting an array of doubles, but it is getting a Point3D structure.

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
That was obvious to the casual observer....LOL. thank you. Just wondering why ug did throw an exception. Maybe, if I wrapped the ufunc with a try-catch block it would have. strange. When inspecting the instance within the debugger of visual studio, the spline object does exist but there where no points associated with it, that should have been my first clue. UG was probably creating a spline with zero length and zero points. Just seems strange that UG didn't throw an exception.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
Meant to say why didn't ug throw an exception when the UFUNC was passed an unexpected data type.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
Back again.

too early too soon. @cowski....the ptData structure is being assigned correctly. Here's the code that does it

For Each iPoint As Point3d In points
pt(0) = iPoint.X
pt(1) = iPoint.Y
pt(2) = iPoint.Z
Console.WriteLine("Point(" & pt(0).ToString() & "," & pt(1).ToString() & "," & pt(2).ToString() & ")")
pts.Add(pt)
Next

The items in the pts array are points dimensioned as doubles.

That's not the problem. Still looking for the problem.
Regards

RE: ufs.curve.createSplineThruPts not being displayed

Nope. I was specifically referring to the highlighted line below. The code you mention does nothing useful.

CODE

For i As Integer = 0 To pts.Count - 1
    ptData(i).point = pts(i)
    ptData(i).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO
    ptData(i).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE
Next 

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

Here's a re-written function that works.

CODE

Public Function makeSpline(ByVal points As System.Collections.ArrayList) As Spline

        Dim ufs As UFSession = UFSession.GetUFSession
        Dim mytag As Tag
        Dim mySpline As Spline = Nothing
        Dim degree As Integer = 3
        Dim periodicity As Integer = 0

        Dim numPoints As Integer = points.Count

        Dim ptData(points.Count - 1) As NXOpen.UF.UFCurve.PtSlopeCrvatr

        For i As Integer = 0 To points.Count - 1
            Dim pt(2) As Double
            pt(0) = points.Item(i).X
            pt(1) = points.Item(i).Y
            pt(2) = points.Item(i).Z

            ptData(i).point = pt
            ptData(i).slope_type = UFConstants.UF_CURVE_SLOPE_AUTO
            ptData(i).crvatr_type = UFConstants.UF_CURVE_CRVATR_NONE
        Next

        '  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)

        MsgBox("Length of Spline = " & mySpline.GetLength)

        Return mySpline

    End Function 

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

I think the way you are adding points to the pts array list is causing the trouble. Since you are re-using the pt() array for each point, the previous values update to the most recently added value. Check the value of each point in the array list to see the issue.

CODE

For Each iPoint As Point3d In points
    pt(0) = iPoint.X
    pt(1) = iPoint.Y
    pt(2) = iPoint.Z
    Console.WriteLine("Point(" & pt(0).ToString() & "," & pt(1).ToString() & "," & pt(2).ToString() & ")")
    pts.Add(pt)
Next
        
'the following results might surprise you
For Each jpoint As Double() In pts
    lw.WriteLine(jpoint(0) & ", " & jpoint(1) & ", " & jpoint(2))
Next 

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
The OO nature of the double variable is re-evaluating all the instances of the double array "pt". If I put the dimension statement inside the for-each loop is makes a new instance of the pt array and doesn't overwrite the previous array. Here's the revised iPoint loop.

CODE --> vb

For Each iPoint As Point3d In points
            Dim pt(2) As Double
            pt(0) = iPoint.X
            pt(1) = iPoint.Y
            pt(2) = iPoint.Z
            pts.Add(pt)
        Next 

RE: ufs.curve.createSplineThruPts not being displayed

My first post was off base and the next ones were hurried and disjointed, but yes, that's what I was getting at. The array is a reference type, since it was declared outside the array you ended up assigning new values to the same memory location. This updated all the values in the array each time you added a new point. Now that the array is declared in the loop, you get a new memory location each time through the loop.

This also answers your previous question as to why no error was thrown. A spline was created with your previous code. It was a degenerate, zero length spline; but it was created.

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
Back Again. The function works for a set of simple points. But doesn't seem to work for these set of points shown below. It's giving an error stating that the points need to be increasing. I've never seen this before. The points are smooth and continuous. Plots in excel easy.

3.166, 0.634, 0
3.1, 0.717, 0
3, 0.841, 0
2.9, 0.962, 0
2.8, 1.079, 0
2.7, 1.193, 0
2.6, 1.302, 0
2.5, 1.406, 0
2.4, 1.504, 0
2.3, 1.596, 0
2.2, 1.68, 0
2.1, 1.755, 0
2, 1.822, 0
1.9, 1.88, 0
1.8, 1.928, 0
1.7, 1.967, 0
1.6, 1.996, 0
1.5, 2.017, 0
1.4, 2.03, 0
1.3, 2.034, 0
1.2, 2.03, 0
1.1, 2.016, 0
1, 1.991, 0
0.9, 1.956, 0
0.8, 1.909, 0
0.8, 1.909, 0
0.7, 1.851, 0
0.6, 1.779, 0
0.5, 1.69, 0
0.4, 1.58, 0
0.3, 1.45, 0
0.213, 1.322, 0

RE: ufs.curve.createSplineThruPts not being displayed

How are you inputting the points?
Text file read in?
Do you have your code for how you convert your data into an array? It's a little bit difficult to advise otherwise.
A quick guess would be not stripping out the leading spaces in your input but that's a wild stab in the dark clown

Mark Benson
Aerodynamic Model Designer

To a Designer, the glass was right on CAD.

RE: ufs.curve.createSplineThruPts not being displayed

First thing I would do is get rid of the ArrayList. An ArrayList is an obsolete collection type that can contain any type of object whatsover, so the compiler can't help you check things. Just use an array of Point3d objects as input. Arrays have a fixed length, but that doesn't seem to present any problems here.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
Those are the points that get printed out within the listing window. Does really matter the origin of the points. The arraylist is not the problem either because the function works if i pass it the points of a parabola like (0,0) , (1, 1^1) , (2,2^2) , (3,3^2) , (4, 4^2) , (5, 5^2). If I plot those points above in excel everything looks great.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
Here's the information in the log file.

NXOpen.NXException: Parameters in spline defining data are not increasing

+++ Parameters in spline defining data are not increasing

Maybe time to submit this one to GTAC.

RE: ufs.curve.createSplineThruPts not being displayed

The point:
0.8, 1.909, 0
appears twice in the list (consecutively). Is this intentional? If you remove the duplicate, the spline is created.

www.nxjournaling.com

RE: ufs.curve.createSplineThruPts not being displayed

> The point: (0.8, 1.909, 0) appears twice in the list (consecutively).

Good eye, Cowski. That's the problem.
I looked for coincident points, but didn't see any.

NX uses the distances between points to assign parameter values to them. If two consecutive points are equal, then the parameter increment between them gets set to zero, so the parameter values are "not increasing". A message saying "coincident points" would be much more helpful.

I still think you should get rid of the ArrayList. ArrayLists are obsolete and evil -- using them prevents the complier from helping you.

RE: ufs.curve.createSplineThruPts not being displayed

(OP)
It works !! Thank you guys. Sometimes when coding your can't see the forest from the trees or the trees from the forest....

I agree a more helpful error message would have been better.

I agree it's kind of sloppy coding to use arrays. But, sometimes I like to bundle up things in list of lists. Then pass the arraylist around and break it apart on the other side. This works great if you are the only one programming but fails when there are multiple programmers. It's better to make a class object. ArrayList are good when you don't know the size of the array. Without knowing the size of the array you have to use redim or redim preserve.

RE: ufs.curve.createSplineThruPts not being displayed

Rather than an Array or ArrayList, I'd suggest using a List(Of {type}); in this case a List(Of Point3d) or List(Of Double()). The List object gives you all the advantages of an ArrayList with the added benefit of type checking.

In this case it's more of a style/preference issue since the ArrayList wasn't the source of any of your problems.

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