×
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

Import lines to NX4

Import lines to NX4

Import lines to NX4

(OP)
Hello every body,
I would like to import lines to a cad model. I have in a worksheet the lines defined by points (x,y). I know how to import those points, but I can´t import a line. It´s possible? for import the points I´m using "file2points" file.

Thanks!!

RE: Import lines to NX4

Would that be the file2points grip program (.grx) or the journal program (.vb)?

www.nxjournaling.com

RE: Import lines to NX4

(OP)
It´s the journal program (.vb)

RE: Import lines to NX4

Inside of NX's database lines are defined simply as two points. So if you have the points imported, that all that you need. Granted, you will now need to actually create the 'line' objects, but you already have the data needed for the job.

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

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

RE: Import lines to NX4

Here is a quick & dirty edit that will import the pairs of points in the file as lines. This may not do exactly what you want, but should serve as an example of how to create the lines from your given points.

CODE

Option Strict Off
Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen

Module Module1

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 workPart As Part = theSession.Parts.Work
Dim sr As StreamReader = New StreamReader(openFileDialog1.FileName)
Dim line As String
Dim startPoint As Point3d
Dim endPoint As Point3d
Dim i As Integer = 0

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)
endPoint.x = Double.Parse(strings(0))
endPoint.y = Double.Parse(strings(1))
endPoint.z = Double.Parse(strings(2))
If Not IsNothing(startPoint) Then
'create a line from startpoint to endpoint
workPart.Curves.CreateLine(startPoint, endPoint)
End If
startPoint = endPoint

'Dim p As Point
'p = session.Parts.Work.Points.CreatePoint(pt)
'p.SetVisibility(SmartObject.VisibilityOption.Visible)

line = sr.ReadLine()
End While
Finally
sr.Close()
End Try
End If
Catch E As Exception
MessageBox.Show(E.Message)
End Try
End Sub


Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

End Function

End Module

www.nxjournaling.com

RE: Import lines to NX4

(OP)
thanks!! I will go to try! I´ve never used the journal before, so I have to try it.

RE: Import lines to NX4

In what format should be the coordinates in the file?
My file looks:

264.560,-259.448,-18.276
263.969,-259.748,-18.302
263.374,-260.040,-18.328
262.776,-260.325,-18.354
262.174,-260.602,-18.380
266.889,-258.178,-18.274

and the result: Input string was not in a correct format.

----
kukelyk

RE: Import lines to NX4

Your test data appears to be in the correct comma delimited format. I ran a test on your posted data and it worked. I suspect this is only a small portion of your data; does the data file have headers or blank lines? If so, they may cause problems. The journal uses Double.Parse to convert input to numbers, if there are other non-numeric characters in the file it may also cause such an error.

www.nxjournaling.com

RE: Import lines to NX4

After I removed all empty lines, the error is the same..mad

----
kukelyk

RE: Import lines to NX4

Can you post the input file that is giving you problems?

www.nxjournaling.com

RE: Import lines to NX4

With the exception of an extra line from (0,0,0) to the first point in the file, it works fine for me.

What language is your computer set to use? I suspect it is a .NET setting that is interpreting your input differently than what my computer is using (reference thread561-315066: creating multiple spheres on imported coordinates for another example). If your computer language is something other than English, perhaps we can "borrow" petulf's fix from the other thread.

Below is the updated code to get rid of that extra line.

CODE

Option Strict Off    
Imports System    
Imports System.IO    
Imports System.Windows.Forms    
Imports NXOpen    

Module Module1    

    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 workPart As Part = theSession.Parts.Work    
                Dim sr As StreamReader = New StreamReader(openFileDialog1.FileName)    
                Dim line As String    
                Dim startPoint As Point3d  = nothing  
                Dim endPoint As Point3d    
                Dim i As Integer = 0    
				Dim firstPass as Boolean = True  
                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)    
                        endPoint.x = Double.Parse(strings(0))    
                        endPoint.y = Double.Parse(strings(1))    
                        endPoint.z = Double.Parse(strings(2))    
                        If firstPass Then  
							firstPass = False  
						Else  
 'create a line from startpoint to endpoint
                            workPart.Curves.CreateLine(startPoint, endPoint)    
                        End If    
                        startPoint = endPoint    

 'Dim p As Point
 'p = session.Parts.Work.Points.CreatePoint(pt)
 'p.SetVisibility(SmartObject.VisibilityOption.Visible)

                        line = sr.ReadLine()    
                    End While    
                Finally    
                    sr.Close()    
                End Try    
            End If    
        Catch E As Exception    
            MessageBox.Show(E.Message)    
        End Try    
    End Sub    


    Public Function GetUnloadOption(ByVal dummy As String) As Integer    

 'Unloads the image when the NX session terminates
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination    

    End Function    

End Module 

www.nxjournaling.com

RE: Import lines to NX4

Thanks, but still not resolved, the same error..

CODE --> TCL

Imports System
Imports System.IO
Imports System.Windows.Forms
Imports NXOpen
Module Test
    Sub Main
                Dim session As Session = Session.GetSession()
                Dim line As String
                    line = "264.560,-259.448,-18.276"
                        Dim pt As Point3d
                       ' Dim delim As Char () = { ","C }
                        Dim delim As Char () = { "," }
                        Dim strings As String () = line.Split(",")
session.ListingWindow.Open    
session.ListingWindow.WriteLine( strings(0) )  
session.ListingWindow.WriteLine( strings(1) )  
session.ListingWindow.WriteLine( strings(2) )  

                        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)
    End Sub
End Module 
gives as a result:
in the info window:
264.560
-259.448
-18.276

error message:
System.FormatException: Input string was not in a correct format.
at System.Number.ParseDouble(String value, NumberStyles options, NumberFormatInfo numfmt)
at System.Double.Parse(String s)
at Test.Main() in C:\Users\kkukely\AppData\Local\Temp\NXJournals3400\journal.vb:line 23

What??
the 23th row is:

pt.x = Double.Parse(strings(0))

----
kukelyk

RE: Import lines to NX4

What language/regional settings is your computer set to use?
In win xp this can be found in the control panel under "Regional and Language options", I'd guess it is in a similar location for more recent versions of windows as well.

www.nxjournaling.com

RE: Import lines to NX4

Really, the problem was in this "Regional and Language options". When I set it to en-US, the Double.Parse runs correctly.

----
kukelyk

RE: Import lines to NX4

Other problem: it is possible to create points in WCS instead of absolute?

----
kukelyk

RE: Import lines to NX4

Other problem: is it possible to create points in WCS instead of absolute?

----
kukelyk

RE: Import lines to NX4

This version should work regardless of your regional setting and it will output the lines relative to the WCS.

CODE

Option Strict Off  
Imports System  
Imports System.IO  
Imports System.Windows.Forms  
Imports NXOpen  
Imports NXOpen.UF  

Module Module1  
	Dim ufs As UFSession = UFSession.GetUFSession  

	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 workPart As Part = theSession.Parts.Work  
				Dim sr As StreamReader = New StreamReader(openFileDialog1.FileName)  
				Dim line As String  
				Dim startPoint As Point3d  = nothing  
				Dim endPoint As Point3d  
				Dim i As Integer = 0  
				Dim firstPass as Boolean = True  
				Dim USculture As system.globalization.CultureInfo = New System.Globalization.CultureInfo("en-US")  
				Try  
					line = sr.ReadLine()  
					While Not line Is Nothing  
						Dim delim As Char() = {","c}  
						Dim strings As String() = line.Split(delim)  
						endPoint.x = Double.Parse(strings(0), USculture)  
						endPoint.y = Double.Parse(strings(1), USCulture)  
						endPoint.z = Double.Parse(strings(2), USCulture)  
						endPoint = Abs2WCS(endPoint)  
						If firstPass Then  
							firstPass = False  
						Else  
 'create a line from startpoint to endpoint
							workPart.Curves.CreateLine(startPoint, endPoint)  
						End If  
						startPoint = endPoint  
						line = sr.ReadLine()  
					End While  
				Finally  
					sr.Close()  
				End Try  
			End If  
		Catch E As Exception  
			MessageBox.Show(E.Message)  
		End Try  
	End Sub  
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'Date:  11/18/2010
'Subject:  Sample NX Open .NET Visual Basic routine : map point from absolute to wcs
'
'Note:  GTAC provides programming examples for illustration only, and
'assumes that you are familiar with the programming language being
'demonstrated and the tools used to create and debug procedures.  GTAC
'support professionals can help explain the functionality of a particular
'procedure, but we will not modify these examples to provide added
'functionality or construct procedures to meet your specific needs.

	Function Abs2WCS(ByVal inPt As Point3d) As Point3d  
		Dim pt1(2), pt2(2) As Double  

		pt1(0) = inPt.X  
		pt1(1) = inPt.Y  
		pt1(2) = inPt.Z  

		ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, pt1, _  
			UFConstants.UF_CSYS_ROOT_WCS_COORDS, pt2)  

		Abs2WCS.X = pt2(0)  
		Abs2WCS.Y = pt2(1)  
		Abs2WCS.Z = pt2(2)  

    End Function   
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
	Public Function GetUnloadOption(ByVal dummy As String) As Integer  

'Unloads the image when the NX session terminates
		GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination  

	End Function  

End Module 

www.nxjournaling.com

RE: Import lines to NX4

Great, many thanks

----
kukelyk

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