Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

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

Two poles of a spline sitting on top of each other 1

Status
Not open for further replies.

CNSZU

Mechanical
Joined
Sep 2, 2005
Messages
318
Location
TW
Hello,

This is an unusual problem and doesn't happen often. When importing curves from a DXF file, the straight lines get converted to "lines" and curved lines get converted to "splines". So far so good. However, sometimes the converted splines are degree 3 and yet when I double click the spline, I see only 3 poles (there should be 4 poles for a 3 degree spline). The listing in the Studio Spline dialog clearly shows 4 poles, so where is the 4th pole? As it turns out, it is hidden beneath one of the other poles, the reason being that the location is almost identical to that pole. Here is an example using the complete listing of Spline Analysis for the troublesome spline:



Information on spline # 1

Closure Status Open
Degree 3
Number of Poles 4
Number of Segments 1
Number of C0 Knots 0
Number of C1 Knots 0
Number of C2 Knots 0
Rational Status Polynomial
Defining Data None

Pole Number 1

Weight = 1.000000000

Coordinates XC = 153.962813699 X = 153.962813699
YC = 102.993465737 Y = 102.993465737
ZC = 0.000000000 Z = 0.000000000

Pole Number 2

Weight = 1.000000000

Coordinates XC = 154.008676533 X = 154.008676533
YC = 102.947602903 Y = 102.947602903
ZC = 0.000000000 Z = 0.000000000

Pole Number 3

Weight = 1.000000000

Coordinates XC = 154.047486569 X = 154.047486569
YC = 102.958199206 Y = 102.958199206
ZC = 0.000000000 Z = 0.000000000

Pole Number 4

Weight = 1.000000000

Coordinates XC = 154.047472097 X = 154.047472097
YC = 102.958195255 Y = 102.958195255
ZC = 0.000000000 Z = 0.000000000
Approximate rho 0.444361561216626

************************************************************



As you can see, the coordinates of pole 3 and pole 4 are almost identical. The difference is only 0.000014472 mm. However in most cases, this is fine for creating extruded features, but causes problems later when exporting the NX part to STEP.

Is there an automated way to "clean up" splines like these by deleting the extraneous poles?

NX9 Win8.1 64bit i7-3770K 16GB Quadro2000
 
If possible, I'd suggest having the supplier of the DXF use IGES. DXF isn't good at handling splines and never has been. I believe if the splines are higher than 3 degrees prior to conversion, DXF will do what you're seeing and "dumb them down" to 3 degrees - feel free to correct me on that.

You're probably going to require a Journal or GRIP/SNAP program to do what you're asking in regards to automating clean up.

Tim Flater
NX Designer
NX 9.0.2.5 Win7 Pro x64 SP1
Intel Xeon 2.53 GHz 6GB RAM
NVIDIA Quadro 4000 2GB
 
Also just noticed that NX9 has a new DXF/DWG import Wizard - you might look at the options tab and see if setting Polylines to lines and arcs helps you out at all.

Tim Flater
NX Designer
NX 9.0.2.5 Win7 Pro x64 SP1
Intel Xeon 2.53 GHz 6GB RAM
NVIDIA Quadro 4000 2GB
 
Actually, the curves are made in Adobe Illustrator, a graphics program, which then exports them to a DXF file. Normally, there is a lot of work to be done to clean up the curves in Illustrator before exporting to DXF, which is fine 90% of the time, and this is the only remaining issue. What seems to happen is that in Illustrator, a curved line, or "path", must have a "direction handle" on each end point for it to export and import properly in NX. If there is a direction handle on only one endpoint, the aforementioned problem occurs. The DXF converter I believe is adding an extra pole in the same spot as the endpoint to represent the missing direction handle. It is too troublesome to add a direction handle for every curve in Illustrator, so I'm trying to find a way to correct the problem in NX instead.

The DXF/DWG wizard won't convert the curves to lines and arcs, but there is a tool in NX called Simplify Curve, which I think does the same thing. However, this will break all the splines up into smaller segments which changes the shape of the original curves and makes it more complicated.

Anyway thanks for clearing things up Tim, I'll see if it's possible to create a journal to do this task.

NX9 Win8.1 64bit i7-3770K 16GB Quadro2000
 
I was afraid you were going to bring Illustrator into the equation - not uncommon to have issues with paths such as the one with which you're dealing. Seems no matter which route you go, you're going to have to put time into something that addresses this. A bummer, I'm sure.

It might be worth it to Google for this, as AI to DXF is a common practice and many are having the same issues such as yourself (cleanup required in CAD). There may be some things you can do in AI prior to exporting that helps importing into NX go a bit more smoothly (no pun intended).

Tim Flater
NX Designer
NX 9.0.2.5 Win7 Pro x64 SP1
Intel Xeon 2.53 GHz 6GB RAM
NVIDIA Quadro 4000 2GB
 
Here is a simple journal for those who are interested in removing 'duplicate' poles from splines:

Code:
'NXSplineCleanup v1.0
'---------------------
'Use this journal to clean up splines imported from a DXF file. 
'Sometimes, imported splines contain an additional pole very close to one of the endpoints causing problems especially when exporting to STEP.
'This journal will remove those poles which are extremely close to any other pole in the same spline.
'Any spline that is modified will be colored in order to easily inspect the modified splines.
'An undo is added in case the result is unsatisfactory.
'Works for NX 8.0 and above.
'Written by CNSZU November 2014.

Option Strict Off
Imports System
Imports NXOpen

Module NXJournal
    Dim numPoles As Integer
    Dim selObjects, selCurves, selLines, selSplines, modSplines, delPoles As Integer
    Dim theSession As Session = Session.GetSession()
    Dim workPart As Part = theSession.Parts.Work
    Dim displayPart As Part = theSession.Parts.Display
    Dim lw As ListingWindow = theSession.ListingWindow
    Dim mySelectedObjects As NXObject()
    Dim studioSplineBuilderEx1 As Features.StudioSplineBuilderEx
    Dim x, y, z, prevX, prevY, prevZ As Double
    Dim i As Integer
    Dim SplineIsDirty As Boolean

    Sub Main()

        'USER OPTIONS
        '---------------------------------------------------------------------------------------------------------
        Dim Dist As Double = 0.0001 ' 'If two or more poles are closer than this distance, only one will remain.
        '---------------------------------------------------------------------------------------------------------
        '---------------------------------------------------------------------------------------------------------
        Dim ColorCleanedSplines As boolean = True 'if you don't want to color cleaned splines, set to 'false'
        '---------------------------------------------------------------------------------------------------------
        '---------------------------------------------------------------------------------------------------------
        Dim CleanupColor As integer = 145 'the new color of the modified spline
        '---------------------------------------------------------------------------------------------------------

        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Select Objects")

        If SelectObjects("Select", mySelectedObjects) = Selection.Response.Ok Then
            
            selObjects = mySelectedObjects.Length

            For Each mySelObj As NXObject In mySelectedObjects

                If TypeOf mySelObj Is Line Then
                    selLines += 1
                End If

                If TypeOf mySelObj Is Spline Then
                    SplineIsDirty = False
                    selSplines += 1

                    studioSplineBuilderEx1 = workPart.Features.CreateStudioSplineBuilderEx(mySelObj)
                  
                    numPoles = studioSplineBuilderEx1.ConstraintManager.Length

                    x = 0
                    y = 0
                    z = 0
                    prevX = 0
                    prevY = 0
                    prevZ = 0

                    i = 0

                    Do 'for every pole

                        Dim GCD As Features.GeometricConstraintData
                        GCD = studioSplineBuilderEx1.ConstraintManager.FindItem(i)

                        x = GCD.Point.Coordinates.X
                        y = GCD.Point.Coordinates.Y
                        z = GCD.Point.Coordinates.Z

                        If x > prevX - Dist And x < prevX + Dist And y > prevY - Dist And y < prevY + Dist And z > prevZ - Dist And z < prevZ + Dist Then

                            SplineIsDirty = True

                            If i = 1 Then 

                                DeletePole(studioSplineBuilderEx1, i) 'delete current pole
                                i -=1

                             end if
                         
                            if i >1 Then

                               DeletePole(studioSplineBuilderEx1, i - 1) 'delete previous pole
                               i -=1

                           End If

                        End If

                        prevX = x
                        prevY = y
                        prevZ = z

                        i += 1

                    Loop While i < numPoles

                    studioSplineBuilderEx1.Commit()
                    studioSplineBuilderEx1.Destroy()

                    If SplineIsDirty = True Then
                        modSplines += 1

                        'COLOR THE FIXED SPLINE
                        if ColorCleanedSplines = true then
                           Dim dispSpline As DisplayableObject
                           dispSpline = mySelObj
                           Dim displayModification1 As DisplayModification
                           displayModification1 = theSession.DisplayManager.NewDisplayModification()
                           displayModification1.NewColor = CleanupColor 
                           Dim objects1(0) As DisplayableObject
                           objects1(0) = dispSpline
                           displayModification1.Apply(objects1)
                           displayModification1.Dispose()
                         end if

                    End If

                End If
            Next

            selCurves = selLines + selSplines

            lw.Open()
            lw.WriteLine("-----------------------")
            lw.WriteLine("NXSplineCleanup v1.0")
            lw.WriteLine("-----------------------")
            lw.WriteLine("Selected Objects: " & selObjects)
            lw.WriteLine("Selected Curves: " & selCurves)
            lw.WriteLine("Selected Lines: " & selLines)
            lw.WriteLine("Selected Splines: " & selSplines)
            lw.WriteLine("-----------------------")
            lw.WriteLine("Cleaned Up Splines: " & modSplines)
            lw.WriteLine("Deleted Poles: " & delPoles)
            lw.WriteLine("-----------------------")
            lw.WriteLine("Process Complete!")

        End If

        lw.Close()

    End Sub

    Sub DeletePole(instudioSplineBuilderEx1 As Features.StudioSplineBuilderEx, inIndex As Integer)

        Dim GCDtoDelete As Features.GeometricConstraintData
        GCDtoDelete = instudioSplineBuilderEx1.ConstraintManager.FindItem(inIndex)
        instudioSplineBuilderEx1.ConstraintManager.Delete(GCDtoDelete)
        numPoles = instudioSplineBuilderEx1.ConstraintManager.Length

        delPoles += 1

    End Sub

    Function SelectObjects(prompt As String, _
               ByRef selObj As NXObject()) As Selection.Response

        Dim theUI As UI = UI.GetUI
        Dim typeArray() As Selection.SelectionType = {Selection.SelectionType.Curves}

        Dim resp As Selection.Response = theUI.SelectionManager.SelectObjects( _
                prompt, "Selection", _
                Selection.SelectionScope.AnyInAssembly, _
                False, typeArray, selObj)

        If resp = Selection.Response.ObjectSelected Or _
                resp = Selection.Response.ObjectSelectedByName Or _
                resp = Selection.Response.Ok Then
            Return Selection.Response.Ok
        Else
            Return Selection.Response.Cancel
        End If

    End Function

End Module


NX9 Win8.1 64bit i7-3770K 16GB Quadro2000
 
A side note on the subject. Some systems such as Illustrator allows you to make a sharp corner on an otherwise smoothly shaped spline. This is internally done by placing multiple points on the same coordinate. In proper cad systems :-) we don't want that since it will produce problems downstream, blends, shells etc. Instead we want a sharp corner there , - "the" spline should be two splines, and therefore produce multiple faces if used/swept etc.


Regards,
Tomas
 
Deleting a pole and decreasing the degree of a spline can cause a significant shape change.

I like the idea of changing the color to highlight what was changed. I'd suggest keeping a copy of the original spline and changing the line font to dashed (or something other than solid) so the user can adjust the remaining pole to better approximate the original spline shape.

www.nxjournaling.com
 
As Cowski said, if you just delete one of the "duplicate" poles, it will significantly change the shape of the curve. What you want to do, I think, is to move the duplicate pole a tiny distance along the vector that leads to the second pole. This will only change the shape of the curve a tiny bit, and will not change its end tangent direction at all. If you have access to the SNAP API, this stuff is very easy. There are good functions for playing with spline poles, which are orders of magnitude simpler than the NX/Open ones.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top