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:
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
' 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