×
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

Automate Spline -> Through Points option
4

Automate Spline -> Through Points option

Automate Spline -> Through Points option

(OP)
Hi all!
P.S: I use NX 6.0.

I see that Record Journal doesn't activate Insert>Curve>"Spline" option for recording.
I have a .dat file in a folder containing x,y,z co ordinates of points. I want to run a journal that allows me to select the .dat files & generates a spline using "ThroughPoints" option only. I insist on ThroughPoints option because the spline passes through all the points instead of just "fitting" into them.
How can I automate it? Please guide!

RE: Automate Spline -> Through Points option

I think you need to convert your dat file to an expressions file. Then inset curve and choose point location by expression, point it to the expressions file and hit enter...

Best regards,

Michaël.

NX8.5.3 + TC Unified 8.3
Win 7 64 bit



RE: Automate Spline -> Through Points option

How many of these splines do you have to create?
I ask because the NX 6 spline command has the capability of creating a spline through points given a .dat file. Creating a journal to mimic this process won't save you much time, if any.

Now if the journal allows you to select a folder full of .dat files and creates a spline for each, that might be useful...

www.nxjournaling.com

RE: Automate Spline -> Through Points option

(OP)
Cowski,
You're right. I want my journal to select a folder full of .dat files and create a spline for each. I need to automate this.
How can I do it? I have almost 200 .dat files that need to construct splines for.
If it's not much that I am asking for, kindly post VB script addressing the same.

Thanks in advance.

RE: Automate Spline -> Through Points option

Can you execute GRIP programs? Is so, could you provide a few of your .dat files so as to see how your data is formatted?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

(OP)
John,
I don't know how to use GRIP.
The .dat files contain only x, y, z coordinates of points delimited by a tab.
Is it possible to do it with GRIP?

RE: Automate Spline -> Through Points option

Yes, I could write a simple GRIP program to do just that.

To test whether you have a GRIP execute license, download the attached file, change the file extension from .zipper to .zip, extract the files and then go to...

File -> Execute -> Grip...

...run the program 'blob.grx'. If it works you should a get a surface representing an octant of an ellipsoid.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

Try recording Insert-->Curve-->Studio Spline, instead. That does have journal support.

But, actually, I think it's easier to use the older spline functions, like NXOpen.UF.Modl.CreateSpline, which is callable from VB, even though it doesn't get recorded. Ask again if you can't figure it out.

If you have Snap, there is Snap.Create.Spline, which is easy to use and nicely documented.

Personally, I wouldn't recommend GRIP unless you're already familiar with it. It could get the job done, but time spent learning GRIP is not a wise investment in your future, IMO.

RE: Automate Spline -> Through Points option

(OP)
John,
It works. But as others are suggesting, I need a VB program for the same, because this action is a part of a list of actions i am trying to automate.

Bubbak,
Studio Spline doesn't fetch data from .dat files. The option is not there in NX 6.
I am looking for perfectly passing a spline through a given set of points from a .dat file.

RE: Automate Spline -> Through Points option

You can call GRIP programs from other programs include Journals.

Can you still provide a few .dat files for testing?

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

By curiosity, i hope that these dat files are examples and not something that you will use in a real model. ?
The splines i get from these dat files are almost straight, and yet still they carry 357 ; 394 and 424 segments.
The amount of data used for this shape is at least 100 x too much and will due to the low accuracy in the dat files induce "waviness" in the splines. Using a fit spline on the same points will produce a good curve. These curves are not good for production.


Regards,
Tomas

RE: Automate Spline -> Through Points option

> Bubbak,
> Studio Spline doesn't fetch data from .dat files.

No, it doesn't. There are two steps: first you read the point data from the file, then you use the point data to create a spline.

These same two steps will be involved no matter what function you call to create the spline.

To get the point data from the file, you have to learn a little bit about the .NET functions for reading text files, like the "ReadAllLines" function. Here is some (untested) code:

CODE --> vb

Option Infer On
Imports Snap

Public Class MyProgram

   Public Shared Sub Main()

      Dim lines As String() = System.IO.File.ReadAllLines("C:\docs\splineData.txt")
      Dim pts As New List(Of Snap.Position)()

      For Each line As String In lines
         Dim coords As String() = line.Split(vbTab)
         Dim x As Double = System.Double.Parse(coords(0))
         Dim y As Double = System.Double.Parse(coords(1))
         Dim z As Double = System.Double.Parse(coords(2))
         pts.Add(New Position(x,y,z)
      Next

      Snap.Create.SplineThroughPoints(pts.ToArray, 3)

   End Sub

End Class 

But this whole exercise is pointless, anyway, because your three sample splines are exactly straight lines.

RE: Automate Spline -> Through Points option

(OP)
Toost,
They are just examples since I am obligated not to share the original data.
Don't worry about the shape of the splines, the real problem here is how to automate the task. :)

RE: Automate Spline -> Through Points option

(OP)
BubbaK,
Snap is not there in NX 6 sad
Is there a way to do this in NX 6?

RE: Automate Spline -> Through Points option

Could you edit the files so that all fields have the same number of characters? In other words, include the trailing zeros.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

I'll look at it tomorrow.

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

> Snap is not there in NX 6
> Is there a way to do this in NX 6?

Replace the Snap calls by NX/Open calls. There's only one line of code that's significant, really: call NXOpen.UF.UFCurve.CreateSplineThruPts instead of Snap.Create.SplineThroughPoints. The NX documentation has an example showing how to use NXOpen.UF.UFCurve.CreateSplineThruPts.

RE: Automate Spline -> Through Points option

OK, attached is a GRIP program which will open a designated folder and will read the data files in the folder and will create a spline, one for each data file read. Now you must enter the full path name to the folder including the folder name but no trailing '\'. The assumption is that the your data files will be formatted exactly the same as your sample files were. This program will read data files with up to 1,000 X,Y,Z records and can create up to 1,000 splines. In other words, you can create 1,000 splines each with 1,000 data points. Note that when the program is finished, you'll get a message stating "End of Data Files". When you select OK in this message dialog, the program will halt.

When you download the file, edit the file extension from '.zipper' to '.zip' before attempting to extract the program files. Note that the source file, 'Spline_from_pts_file.grs', is fully commented so if you're interested you can see what the program does and how it does it.

Anyway, let me know if it worked for you (I did test this using NX 6.0).

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

(OP)
BubbaK,
I looked up NX documentation, i added system and open namespaces, added references to the module; yet the code doesn't accept "NXOpen.UF.UFCurve.CreateSplineThruPts". I cannot see ".CreateSplineThruPts" method in UFCurve class. How to add it?

RE: Automate Spline -> Through Points option

(OP)
John,
I tried executing the grx file. The splines are not joining all the points, they seem to be scattered. I ran the program for 3 dat files, please see the attached image of the output. Also, UG is responding very slowly. Is there any setting that I need to change?

RE: Automate Spline -> Through Points option

Did you test it using the three data files you provided me?

When I ran it using NX 6.0 on my laptop and using the three data files provided, it took less than a second to create the three splines. This is what the results looked like when I did a 'Fit' after the program ran:

John R. Baker, P.E.
Product 'Evangelist'
Product Engineering Software
Siemens PLM Software Inc.
Digital Factory
Cypress, CA
Siemens PLM:
UG/NX Museum:

To an Engineer, the glass is twice as big as it needs to be.

RE: Automate Spline -> Through Points option

2
Here's how to call CreateSplineThruPts:

CODE --> vb

Shared Sub CreateSplineThroughPoints(qpts As NXOpen.Point3d())

   Dim n As Integer = qpts.Length

   Dim tangentTypes(n-1) As Integer
   Dim curvatureTypes(n-1) As Integer
   Dim tangentVectors(3*n - 1)   As Double
   Dim curvatureVectors(3*n - 1) As Double

   For i As Integer = 0 To n - 1
      tangentTypes(i)   = NXOpen.UF.UFConstants.UF_CURVE_SLOPE_NONE
      curvatureTypes(i) = NXOpen.UF.UFConstants.UF_CURVE_CRVATR_NONE
   Next

   Dim pointData As NXOpen.UF.UFCurve.PtSlopeCrvatr() = New NXOpen.UF.UFCurve.PtSlopeCrvatr(n - 1) {}

   For i As Integer = 0 To n - 1
      pointData(i) = New NXOpen.UF.UFCurve.PtSlopeCrvatr()
      pointData(i).point = New Double(2) {}
      pointData(i).point(0) = qpts(i).X
      pointData(i).point(1) = qpts(i).Y
      pointData(i).point(2) = qpts(i).Z
      pointData(i).slope_type = tangentTypes(i)
      pointData(i).slope = New Double(2) {}
      pointData(i).crvatr_type = curvatureTypes(i)
      pointData(i).crvatr = New Double(2) {}
   Next

   Dim save As Integer = 0    ' Don't save input defining data with the created spline. 
   Dim splineTag As NXOpen.Tag
   Dim parameters As Double() = Nothing
   Dim periodicity As Integer = 0  '  0=non-periodic, 1=periodic

   Dim ufs As NXOpen.UF.UFSession = NXOpen.UF.UFSession.GetUFSession
   ufs.Curve.CreateSplineThruPts(3, periodicity, n, pointData, parameters, save, splineTag)
   ufs.So.SetVisibilityOption(splineTag, NXOpen.UF.UFSo.VisibilityOption.Visible)

End Sub 

RE: Automate Spline -> Through Points option

(OP)
John & BubbaK,
Thanks to you both. Both methods work!! Thanks a lot :)
I restarted my system & grx program worked fine.

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