Importing points from a text file into a sketch

asked in General Forum by (180 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.


Please log in or register to answer this question.

2 Answers

0 votes
answered by (9.8k 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)



This file will import 4 points on listed coordinates.



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

Module Test

    Sub Main
           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

                    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)
                        line = sr.ReadLine()
                    End While
                End Try
            End If
        Catch E As Exception
        End Try
    End Sub
End Module  

+1 vote
answered by (180 points)

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.
Welcome to
Share a new topic or ask a question.

558 questions

405 answers


94.9k users