Showing results for 
Search instead for 
Did you mean: 

NX - Points coordinates in Draft table


Dear All,


does anyone of you have some useful journal / macro for listing point X, Y, Z coordinates to a table in draft file.


For e.g., you have a simple part (or assm) with few CSYS, and few points. In draft you want to list selected points coordinates (X,Y,Z) from selected CSYS. Another (more simple) alternative would be to list all points coordinates from an absolute coordinate system.


Unfortunately, I dont have experience with journaling and maybe some of you have something already done.


Re: NX - Points coordinates in Draft table

Here is a journal for the simple case of using the points in the work part.  The first few lines would need to be changes for whatever you need to collect the desired point data that you need for your table.


Option Strict Off
Imports System
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpenUI
Imports NXOpen.UF
Imports NXOpen.Utilities

Module AllPointsToTable
    Dim s As Session = Session.GetSession()
    Dim ui As UI = ui.GetUI()
    Dim ufs As UFSession = UFSession.GetUFSession()
    Dim wp As Part = s.Parts.Work()
    Sub Main()
        Dim allpoints As PointCollection = wp.Points
        Dim newpoints() As Point = allpoints.ToArray
        Dim newpoints3d(newpoints.Length - 1) As Point3d
        For i As Integer = 0 To newpoints.Length - 1
            newpoints3d(i) = newpoints(i).Coordinates
        Dim cursor As Point3d = New Point3d
        ' select point for tabnote
        Dim dwgview As View = Nothing

        Dim response As Selection.DialogResponse = SelectScreenPos(cursor, dwgview)
        If response <> Selection.DialogResponse.Pick Then
        End If
        ' Create the tabular note
        Dim n_new_columns As Integer = 4
        Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(0, n_new_columns, cursor)
        ' Get the column tags
        Dim columns(n_new_columns - 1) As NXOpen.Tag
        For ii As Integer = 0 To n_new_columns - 1
            ufs.Tabnot.AskNthColumn(tabnote, ii, columns(ii))
        Dim row As NXOpen.Tag
        Dim cell As NXOpen.Tag
        Dim cells(3) As NXOpen.Tag
        ' Add points Header Row
        Dim headerrow As NXOpen.Tag
        ufs.Tabnot.CreateRow(10, headerrow)
        ufs.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)
        ufs.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
        ufs.Tabnot.SetCellText(cell, "Point")
        ufs.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell)
        ufs.Tabnot.SetCellText(cell, "     X     ")
        ufs.Tabnot.AskCellAtRowCol(headerrow, columns(2), cell)
        ufs.Tabnot.SetCellText(cell, "     Y     ")
        ufs.Tabnot.AskCellAtRowCol(headerrow, columns(3), cell)
        ufs.Tabnot.SetCellText(cell, "     Z     ")
        ' Add a row for each point leaving out the first point ???
        For i As Integer = 0 To newpoints.Length - 1
            ufs.Tabnot.CreateRow(10, row)
            ufs.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
            ufs.Tabnot.AskCellAtRowCol(row, columns(0), cell)
            ufs.Tabnot.SetCellText(cell, (i + 1).ToString())
            ufs.Tabnot.AskCellAtRowCol(row, columns(1), cell)
            ufs.Tabnot.SetCellText(cell, FormatNumber(newpoints3d(i).X, 1).ToString())
            ufs.Tabnot.AskCellAtRowCol(row, columns(2), cell)
            ufs.Tabnot.SetCellText(cell, FormatNumber(newpoints3d(i).Y, 1).ToString())
            ufs.Tabnot.AskCellAtRowCol(row, columns(3), cell)
            ufs.Tabnot.SetCellText(cell, FormatNumber(newpoints3d(i).Z, 1).ToString())

    End Sub

    Public Function CreateTabnoteWithSize( _
        ByVal nRows As Integer, ByVal nColumns As Integer, ByVal loc As Point3d) As NXOpen.Tag
        ' Create the tabular note.  Based on annotation preferences Fit methods with auto size row on, auto size text on, 
        ' auto size column on and all others off
        Dim secPrefs As UFTabnot.SectionPrefs = Nothing
        Dim origin(2) As Double
        origin(0) = loc.X
        origin(1) = loc.Y
        origin(2) = loc.Z
        Dim tabnote As NXOpen.Tag
        ufs.Tabnot.Create(secPrefs, origin, tabnote)
        ' Delete all existing columns and rows (we create them as needed)
        Dim nmRows As Integer = 0
        ufs.Tabnot.AskNmRows(tabnote, nmRows)
        For ii As Integer = 0 To nmRows - 1
            Dim row As NXOpen.Tag
            ufs.Tabnot.AskNthRow(tabnote, 0, row)
        Dim nmColumns As Integer = 0
        ufs.Tabnot.AskNmColumns(tabnote, nmColumns)
        For ii As Integer = 0 To nmColumns - 1
            Dim column As NXOpen.Tag
            ufs.Tabnot.AskNthColumn(tabnote, 0, column)
        ' Now add our columns as needed
        Dim columns(nColumns - 1) As NXOpen.Tag
        For ii As Integer = 0 To nColumns - 1
            '   ufs.Tabnot.SetColumnWidth(columns(ii), 10)
            ufs.Tabnot.CreateColumn(40, columns(ii))
            ufs.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
        ' Now add our rows as needed
        Dim rows(nRows - 1) As NXOpen.Tag
        For ii As Integer = 0 To nRows - 1
            ufs.Tabnot.CreateRow(40, rows(ii))
            ufs.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)
        Return tabnote
    End Function
    Public Function SelectScreenPos(ByRef pos As Point3d, ByVal view As View) As Selection.DialogResponse
        Return (ui.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos))
    End Function
    Public Function GetUnloadOption(ByVal dummy As String) As Integer
        'Unloads the image immediately after execution within NX
        GetUnloadOption = NXOpen.Session.LibraryUnloadOption.Immediately
    End Function

End Module


Frank Swinkels

Re: NX - Points coordinates in Draft table


Hi Frank,


I tested it and it works if you do modeling and draft in one file. If you are referencing part in draft it does not work. It still needs some changes, but this is good way to start. Thank you for your help!