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!!
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
www.nxjournaling.com
RE: Import lines to NX4
RE: Import lines to NX4
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
CODE
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
RE: Import lines to NX4
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
www.nxjournaling.com
RE: Import lines to NX4
----
kukelyk
RE: Import lines to NX4
www.nxjournaling.com
RE: Import lines to NX4
----
kukelyk
RE: Import lines to NX4
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
www.nxjournaling.com
RE: Import lines to NX4
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 Modulein 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
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
----
kukelyk
RE: Import lines to NX4
----
kukelyk
RE: Import lines to NX4
----
kukelyk
RE: Import lines to NX4
CODE
www.nxjournaling.com
RE: Import lines to NX4
----
kukelyk