Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

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

Extract XYZ points with a Journal file (with NX names) 1

Status
Not open for further replies.

MartijnH

Mechanical
Sep 24, 2013
18
I have spend a long time searching this forum and I have found some code that exports the coordinates of points (thread561-314774). However, this journal does not export the name as given in the part navigator of NX. The code I use is:

Code:
' NX 7.5.0.32
' eng-tips thread561-314774
' 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
 
Replies continue below

Recommended for you

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 Module

www.nxjournaling.com
 
In addition to this function, I would like to have not only the x,y,z coordinates, but as well the orientations of the coordinate systems w.r.t. to the global coordinate system. Does anyone has a suggestion for this?
 
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 Module

www.nxjournaling.com
 
Hi Cowski,

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:
Global,0,0,0,1,0,0,0,1,0,0,0,1
CS_ARC_RAD_1,-0.39228,0.891514,0.179,0,0,-1,-0.915309794292228,-0.402750518898139,0,-0.402750518898139,0.915309794292228,0
In which the first argument is the name, next are the 3 coordinates which are followed by 3x3 values for the direction matrix.

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

Part and Inventory Search

Sponsor