Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

https://www.eng-tips.com/viewthread.cfm?qid=314774

Status
Not open for further replies.

NGMatt

Aerospace
Sep 11, 2013
21
I've searched high and low and maybe I skipped write over it but how can I create a vb journal to extract points (non-timestamp geometry) to a file with the point name? I'm talking about a point that has been renamed (i.e. Point "PNT1") in non-timestamp geometry. A couple of these come close but I haven't found one yet:


This code outputs points but no name.
Code:
'
' This journal should write the XYZ values of all points in the
' work part to a new .dat file.
'
' It will drop the ".prt" from the file name and append "_points.dat".
'
' As written, it separates the fields with a comma and a space, 
' but you can easily change that.
'
' Also, note that the "F6" specifies that 6 digits will be shown to the 
' right of the decimal, even if they are all zeroes.  
' You can change that too, of course.
'
 
Option Strict Off
 
Imports System
Imports NXOpen
 
Module Points2File
 
   Public s As Session = Session.GetSession()
 
   Sub Main()
 
      Dim workPart As Part = s.Parts.Work
      Dim thePoints As PointCollection = workPart.Points
      Dim wpName As String = workPart.FullPath.ToString()
      Dim textFileName As String = Nothing
 
      textFileName = wpName.Replace(".prt", "_points.dat")
 
      Dim outFile As IO.StreamWriter
 
      outFile = My.Computer.FileSystem.OpenTextFileWriter(textFileName, _
                                                                    False)
      outFile.AutoFlush = True
 
      For Each thisPoint As Point In thePoints
 
         outFile.WriteLine(thisPoint.Coordinates.X.ToString("F6") & ", " & _
                           thisPoint.Coordinates.Y.ToString("F6") & ", " & _
                           thisPoint.Coordinates.Z.ToString("F6"))
 
      Next
 
      outFile.Close()
 
      MsgBox("Text File Name: " & textFileName, MsgBoxStyle.Information)
 
   End Sub
 
   Public Function GetUnloadOption(ByVal dummy As String) As Integer
 
      Return Session.LibraryUnloadOption.Immediately
 
   End Function
 
End Module



Here is another thread but again no point name:
 
Replies continue below

Recommended for you

Most objects have a ".Name" property that you can access. In the outFile.WriteLine code, you can add "thisPoint.Name" where you would like it to appear.

www.nxjournaling.com
 
I've seen the code you are referring to when creating a new point name. However, I am still unable to extract the existing renamed (non-timestamp geometry) point and output that via writeline. Any help would be appreciated. Thanks
 
If you want the name to appear first on the output line, you could change the for loop code above to:

Code:
For Each thisPoint As Point In thePoints

   outFile.WriteLine(thisPoint.Name & "," & _ 
                     thisPoint.Coordinates.X.ToString("F6") & ", " & _
                     thisPoint.Coordinates.Y.ToString("F6") & ", " & _
                     thisPoint.Coordinates.Z.ToString("F6"))

Next

Note that the code in the above posts will process all the points in the file whether they are timestamp geometry or not. If you want to find only the non-timestamp (unassociative) points, you can use the .AskObjectFeat method. The code in the link below shows how to call the .AskObjectFeat method; it works with line objects, but the concept is the same for points.


www.nxjournaling.com
 
Awesome. That works perfectly. Thankyou.
 
This code has been working great. Now I have an issue because I need to import and export from the local coordinate system and not the main coordinate system. In other words I import 2,0,0 and these points show up way out in left field regardless of where my active WCS is defined. How can I specify a explicit coordinate system to import/export to?
 
thread561-427371

In the first post of the thread above, there are functions that will convert point coordinates between the absolute and local coordinate systems.

www.nxjournaling.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor