×
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

Adding points from textfile in sketch: journal

Adding points from textfile in sketch: journal

Adding points from textfile in sketch: journal

(OP)
Hello guys...

I'm trying to addapt the file2points vb (from sample nxopen) to work inside a sketch.
I changed 2 lines (originals commented out) in below vb but I get an tag not allowed error

CODE --> VB

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 = session.Parts.Work.Points.CreatePoint(pt)
                        'p.SetVisibility(SmartObject.VisibilityOption.Visible)
			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 

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11

RE: Adding points from textfile in sketch: journal

Try the following:

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 

www.nxjournaling.com

RE: Adding points from textfile in sketch: journal

(OP)
Hi Cowski,

Thanks, that worked..
I see I shouldn't have removed the declaration of p

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11

RE: Adding points from textfile in sketch: journal

Yes, that line of code actually creates the point object and the ActiveSketch.AddGeometry method adds the point object to the sketch. One other item of note: if you simply uncomment the line in your code, it will still return an error. This is because that particular line attempts to reference a variable named "session", but the variable referencing the NX Session object was actually declared as "theSession". The compiler will complain that it can't find the "session" variable.

www.nxjournaling.com

RE: Adding points from textfile in sketch: journal

(OP)
Thanks! Had that the first time indead..luckily I could figure it out myself.. :)

Ronald van den Broek
Senior Application Engineer
Winterthur Gas & Diesel Ltd
NX9 / TC10.1.2

Building new PLM environment from Scratch using NX11 / TC11

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