Extract XYZ points with a Journal file (with NX names)
Extract XYZ points with a Journal file (with NX names)
(OP)
I have spend a long time searching this forum and I have found some code that exports the coordinates of points (thread561-314774: Extract XYZ points from a Journal file.). However, this journal does not export the name as given in the part navigator of NX. The code I use is:
I would like to use this code to export the xyz coordinates of several CSYS which I added myself together with the name I give it in NX (in the part navigator). However, to export a name I have to change the object properties of the CSYS and add a TITLE "NM" with VALUE "desired name". How can I export the name without doing this?
I've found the following code to export the name, but I cannot get into the coordinates. So both options only give me half of the solution.
I hope someone can help me with this problem?
I'm working with NX75
CODE
' NX 7.5.0.32 ' eng-tips thread561-314774: Extract XYZ points from a Journal file.: Extract XYZ points from a Journal file. ' return information on points and arcs for bend table info Option Strict Off Imports System Imports System.Collections Imports NXOpen Imports NXOpenUI Imports NXOpen.UF Module NXJournal Dim ufs As UFSession = UFSession.GetUFSession() Sub Main Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim displayPart As Part = theSession.Parts.Display 'layer to interrogate dim layerNumber as Integer = 1 Dim lw As ListingWindow = theSession.ListingWindow Dim allObjects as NXObject() Dim pointObject as Point Dim pointXYZ as Point3d Dim myPoints as New ArrayList() Dim pointName as String allObjects = workPart.Layers.GetAllObjectsOnLayer(layerNumber) lw.Open for each someObject as NXObject in allObjects if someObject.GetType.ToString = "NXOpen.Point" then myPoints.Add(someObject) end if next 'myPoints.Sort 'info dump, not guaranteed to be in any specific order lw.WriteLine("Point Name,Point X,Point Y,Point Z, all in millimeters") for each pointObject in myPoints pointXYZ = pointObject.Coordinates pointXYZ = Abs2WCS(pointXYZ) Try pointName = pointObject.GetStringAttribute("NM") Catch 'attribute does not exist pointName = "<NM>" End Try lw.WriteLine(pointName & "," & Math.Round(pointXYZ.X, 3) & "," & Math.Round(pointXYZ.Y, 3) & "," & Math.Round(pointXYZ.Z, 3)) next lw.WriteLine("") lw.Close End Sub '************************************************************************************************** 'function taken from GTAC example 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 '************************************************************************************************** End Module
I would like to use this code to export the xyz coordinates of several CSYS which I added myself together with the name I give it in NX (in the part navigator). However, to export a name I have to change the object properties of the CSYS and add a TITLE "NM" with VALUE "desired name". How can I export the name without doing this?
I've found the following code to export the name, but I cannot get into the coordinates. So both options only give me half of the solution.
CODE
Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Features
Module NXJournal
Sub Main
Dim s As Session = Session.GetSession()
Dim ui As UI = UI.GetUI()
Dim lw As ListingWindow = s.ListingWindow
Dim pointTest as Point3d
lw.Open()
Dim featArray() As Feature = s.Parts.Work.Features.GetFeatures()
lw.WriteLine("*** All Features ***")
For each myFeature as Feature in featArray
if myFeature.GetType.ToString = "NXOpen.Features.DatumCsys" then
lw.WriteLine(myFeature.Name)
end if
Next
lw.Close
End Sub
End Module I hope someone can help me with this problem?
I'm working with NX75





RE: Extract XYZ points with a Journal file (with NX names)
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Features Module Module5 Sub Main() Dim s As Session = Session.GetSession() Dim lw As ListingWindow = s.ListingWindow lw.Open() lw.WriteLine("*** Datum Csys Features ***") For Each myFeature As Feature In s.Parts.Work.Features If TypeOf (myFeature) Is Features.DatumCsys Then lw.WriteLine("name: " & myFeature.Name) lw.WriteLine(myFeature.Location.ToString) lw.WriteLine("") End If Next lw.Close() End Sub End Modulewww.nxjournaling.com
RE: Extract XYZ points with a Journal file (with NX names)
RE: Extract XYZ points with a Journal file (with NX names)
RE: Extract XYZ points with a Journal file (with NX names)
NX 8.5.1.3
RE: Extract XYZ points with a Journal file (with NX names)
CODE
Option Strict Off Imports System Imports NXOpen Imports NXOpen.Features Module Module1 Sub Main() Dim theSession As Session = Session.GetSession() Dim workPart As Part = theSession.Parts.Work Dim lw As ListingWindow = theSession.ListingWindow lw.Open() lw.WriteLine("*** Datum Csys Features ***") For Each myFeature As Feature In workPart.Features If (TypeOf (myFeature) Is Features.DatumCsys) AndAlso (Not myFeature.IsInternal) Then Dim DBuilder As DatumCsysBuilder DBuilder = workPart.Features.CreateDatumCsysBuilder(myFeature) lw.WriteLine("feature: " & myFeature.GetFeatureName) lw.WriteLine("name: " & myFeature.Name) lw.WriteLine(myFeature.Location.ToString) lw.WriteLine(DBuilder.Csys.Orientation.Element.ToString) lw.WriteLine("") DBuilder.Destroy() End If Next lw.Close() End Sub Public Function GetUnloadOption(ByVal dummy As String) As Integer 'Unloads the image when the NX session terminates GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination '----Other unload options------- 'Unloads the image immediately after execution within NX 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately 'Unloads the image explicitly, via an unload dialog 'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Explicitly '------------------------------- End Function End Modulewww.nxjournaling.com
RE: Extract XYZ points with a Journal file (with NX names)
This is a nice addon. I implemented this code into my script. For simplicity (I want to extract data from this created output) I've put all the output of one CSYS in one line. This now looks like:
CODE -->
I run into a problem when the length of one line is over 132 characters. It then places the remaining characters on a new line with a hardcoded 'enter'. My matlab read-out script then runs into an error. Is it possible to increase the number of characters that are placed on one line? Or is there an other option to avoid the listingwindow and directly write to a file?
RE: Extract XYZ points with a Journal file (with NX names)
You can skip the part about the listing window and go straight to the StreamWriter section.
www.nxjournaling.com