Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Adding points from textfile in sketch: journal

Status
Not open for further replies.

NutAce

Mechanical
Apr 22, 2010
1,192
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:
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)
[b]			theSession.ActiveSketch.AddGeometry(p, Sketch.InferConstraintsOption.InferNoConstraints)
			theSession.ActiveSketch.Update()[/b]
                        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
 
Replies continue below

Recommended for you

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
 
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
 
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
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor