Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

ufs.curve.createSplineThruPts not being displayed

Status
Not open for further replies.

EngProgrammer

Aerospace
Jan 14, 2015
150
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?
 
Replies continue below

Recommended for you

> 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.
 
Code:
    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
 
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.
 
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
 
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.
 
Meant to say why didn't ug throw an exception when the UFUNC was passed an unexpected data type.
 
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
 
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
    [highlight #FCE94F]ptData(i).point = pts(i)[/highlight]
    ptData(i).slope_type = UF.UFConstants.UF_CURVE_SLOPE_AUTO
    ptData(i).crvatr_type = UF.UFConstants.UF_CURVE_CRVATR_NONE
Next

www.nxjournaling.com
 
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
 
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
 
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:
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
 
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
 
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
 
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 :eek:)

Mark Benson
Aerodynamic Model Designer

To a Designer, the glass was right on CAD.
 
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.
 
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.
 
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.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor