Importing points from a text file into a sketch

posted by Mar 10 in General Forum by edi (160 points)
Hello everybody,

This is my first post. I've been using NX for couple of weeks now. I have a problem and I hope that someone has a solution to it. I want to create an object by spline through points. I can import the points from a text file using import function and then spline through them. However, the import function places the point somewhere in the GUI and this is not what I desire. I want the point to be placed in a specified sketch. I can't find any option in the create point function either which would allow me to create points from a text file. How can I solve this problem.

Thanks

Please log in or register to answer this question.

2 Answers

0 votes
answered Mar 15 by Ronaldvandenbroek (9,690 points)

Siemens has an example in their NXopen examples (NX installation folder) for importing points from a external file.
I (with some expert help) have been able to adapt it such that it will import the points in an active sketch.

When you run this VB journal it will ask you to point to a file where you have given the coordinates of the points you want to import. (file has to be in below format)

Text file with; (x,y,z)

0,0,0
10,0,0
10,10,0
0,10,0

 

This file will import 4 points on listed coordinates.

 

Code:

Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen

Module Test

    Sub Main
        Try
           Dim openFileDialog1 As New OpenFileDialog()
       
            openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*"
            openFileDialog1.FilterIndex = 1
            openFileDialog1.RestoreDirectory = True
       
            If openFileDialog1.ShowDialog() = DialogResult.OK Then
                Dim theSession As Session = Session.GetSession()
                Dim sr As StreamReader = new StreamReader(openFileDialog1.FileName)
                Dim line As String

                Try
                    line = sr.ReadLine()
                    While Not line is Nothing
                        Dim pt As Point3d
                        Dim delim As Char () = { ","c }
                        Dim strings As String () = line.Split(delim)
                        pt.x = Double.Parse(strings(0))
                        pt.y = Double.Parse(strings(1))
                        pt.z = Double.Parse(strings(2))
                        Dim p As Point
                        p = theSession.Parts.Work.Points.CreatePoint(pt)
            theSession.ActiveSketch.AddGeometry(p, Sketch.InferConstraintsOption.InferNoConstraints)
            theSession.ActiveSketch.Update()
                        line = sr.ReadLine()
                    End While
                Finally
                    sr.Close()
                End Try
            End If
        Catch E As Exception
            MessageBox.Show(E.Message)
        End Try
    End Sub
End Module  

0 votes
answered Mar 17 by edi (160 points)
Hello,

Thanks for your response. I've used your journal but the problem is still there. The origin of the sketch that I want to import the points to is different from the datum coordinate system and the points are referenced from the datum coordinate system. I don't know why NX can't handle this very simple operation of Importing points into a sketch. This is really a bad experience.

511 topics

379 answers

133 comments

11,102 users

...