Point Co-ordinates Tabular note

Hi, below is the modified version of the Journal "point co-ordinates tabular note" by Cowski from eng-tips. (unable to trace the exact link to the original code.)
I have made below changes to the code:
1> Journal will select only the points which are visible in the view, irrespective of the any number of points in the view.
2> Rather than assigning points ID's, the point names(from 3D point object name) are associated to the co-ordinate values. (Before running this journal, 3D Point objects have to be assigned a name. Else the Point names would be blank).
3> Made a custom sort to the point names so that the points looks grouped.
(Sort works fine when the number at the end of the point name do not exceed 09. Used a crude approach for a custom sort of Point "Name" by reversing the string , sort the reversed string and then reverse the string again)

The source code was a very much useful reference and helped a lot for a beginner like me with some experimenting.

Now, i'am stuck with this code where i want to make small improvements.
How can i adjust the column width. I have 5 columns: and I want Column 1, Column 2 of different width and columns 3 to 5 of same width.

Also, the points are not associative, which i'am trying to make associative. Not sure if I would come back with a solution or a query to make the co-ordinates associative. :):)

' NX 12.0.1.7
' Journal created by Balaji_Sampath03 on Mon Jul 13 20:50:40 2020 India Standard Time

'**************************************************************************************
'This Macro creates the co-ordinate point table for all visible drafting points in the view
'Corresponding Point Names are also inserted in the table
'Points are custom sorted before tabulating the co-ordinates
'Points are tabulated in Global Co-ordinate system
'***************************************************************************************
Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports System.Linq

Module Tab_Coordinates

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim theUI As UI = UI.GetUI()
'Dim displayPart As Part = theSession.Parts.Display
Dim theDraftView As Drawings.DraftingView
Dim ptsPoints As New List(Of Point)
Dim ptsNames As New List(Of String)
Dim revNames As New List(Of String)
Dim viewName As String = Nothing
Dim ptsCount As Integer = "0"
Dim tempName As String = Nothing
Dim lw As ListingWindow = theSession.ListingWindow

Sub Main (ByVal args() As String)

lw.Open()
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Co-Ordinates Table")

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel

viewName = theDraftView.Name

'Check for the points and points to list: Exit if there is no point
'------------------------------------------------------------------
For Each tempObj As DisplayableObject In theDraftView.AskVisibleObjects
If TypeOf tempObj Is Point Then
ptsPoints.Add(tempObj)
tempObj.Highlight
End If
Next

If ptsPoints.ToArray().Length = 0 Then
lw.Open()
lw.WriteLine("No Points found. Exit.")
Return
End If

'Get location for Co-ordinates Table
'-----------------------------------
Dim cursor As Point3d
Dim response As Selection.DialogResponse = SelectScreenPos(cursor)
If response <> Selection.DialogResponse.Pick Then
Return
End If

'Reverse String before Sort
'--------------------------
For Each tempObj As Point In ptsPoints
'If custom sort is not needed comment out the below two lines and un-comment the last line of the loop
'and comment the StrReverse code in Line 154 and un-comment the line 155
Dim revName As String = StrReverse(tempObj.Name)
ptsNames.Add(revName)
'ptsNames.Add(tempObj.Name)
Next

' Sort All point Names
'------------------------
ptsNames.Sort(AddressOf ComparePointNames)

' Create the tabular note
'------------------------
Dim n_new_columns As Integer = 5
Dim n_new_rows As Integer = 0
Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(n_new_rows, 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
theUfSession.Tabnot.AskNthColumn(tabnote, ii, columns(ii))
Next
Dim cell As NXOpen.Tag

' Add Title Row
'--------------
Dim TitleRow As Tag
Dim height As Double = Nothing
Dim cellprefes As UFTabnot.CellPrefs = Nothing
Dim cell1 As NXOpen.Tag
Dim cell2 As NXOpen.Tag
Dim cell3 As NXOpen.Tag
Dim cell4 As NXOpen.Tag

theUfSession.Tabnot.CreateRow(30, TitleRow)
theUfSession.Tabnot.AddRow(tabnote, TitleRow, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(2), cell1)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(4), cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell3)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(1), cell4)
theUfSession.Tabnot.MergeCells(cell1, cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell1, "Koordinaten von Ebenen RX,RY,RZ Coordinates from Planes RX, RY, RZ")

' Add Header Row
'---------------
Dim headerrow As NXOpen.Tag
Dim cell5 As NXOpen.Tag
Dim cell6 As NXOpen.Tag

theUfSession.Tabnot.CreateRow(30, headerrow)
theUfSession.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, "Kontrollmass Check Dimension")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell)
theUfSession.Tabnot.SetCellText(cell, "Schnitt Section")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, "X")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, "Y")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, "Z")

theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell5)
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell6)
theUfSession.Tabnot.MergeCells(cell3, cell5)
theUfSession.Tabnot.MergeCells(cell4, cell6)

' Add a row for each point
'-------------------------
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing

For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1

Dim row As NXOpen.Tag
theUfSession.Tabnot.CreateRow(30, row)
theUfSession.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(row, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, StrReverse(ptsNames.Item(i)))
'theUfSession.Tabnot.SetCellText(cell, ptsNames.Item(i))

' Set the cell text
'------------------
Dim ordVal(2) As String

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3")
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3")
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3")

theUfSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(0))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(1))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(2))
Next

' Clear Points & Name List
'-------------------------
ptsPoints.Clear()
ptsNames.Clear()

'Clear Selection List
'--------------------

Dim partCleanup As NXOpen.PartCleanup = Nothing
partCleanup = theSession.NewPartCleanup()
partCleanup.TurnOffHighlighting = True
partCleanup.DoCleanup()
partCleanup.Dispose()

Loop

End Sub

Function SelDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a drafting view"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selView = CType(selObj, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse
Dim theUI As UI = UI.GetUI()
Dim view As NXOpen.View = Nothing
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Return theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)
End Function

Public Function CreateTabnoteWithSize(ByVal nRows As Integer,
ByVal nColumns As Integer,
ByVal loc As Point3d) As NXOpen.Tag

Try
' Create the tabular note
Dim secPrefs As UFTabnot.SectionPrefs
theUfSession.Tabnot.AskDefaultSectionPrefs(secPrefs)
Dim cellPrefs As UFTabnot.CellPrefs
theUfSession.Tabnot.AskDefaultCellPrefs(cellPrefs)
cellPrefs.zero_display = UFTabnot.ZeroDisplay.ZeroDisplayZero
cellPrefs.line_space_factor = 1.0
cellPrefs.nm_fit_methods = 3
'cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodAutoSizeRow
'cellPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodAutoSizeCol
cellPrefs.fit_methods(2) = UFTabnot.FitMethod.FitMethodWrap
theUfSession.Tabnot.SetDefaultCellPrefs(cellPrefs)

Dim origin(2) As Double
origin(0) = loc.X
origin(1) = loc.Y
origin(2) = loc.Z
Dim tabnote As NXOpen.Tag
theUfSession.Tabnot.Create(secPrefs, origin, tabnote)

' Delete all existing columns and rows (we create them as needed)
Dim nmRows As Integer = 0
theUfSession.Tabnot.AskNmRows(tabnote, nmRows)
For ii As Integer = 0 To nmRows - 1
Dim row As NXOpen.Tag
theUfSession.Tabnot.AskNthRow(tabnote, 0, row)
theUfSession.Tabnot.RemoveRow(row)
theUfSession.Obj.DeleteObject(row)
Next

Dim nmColumns As Integer = 0
theUfSession.Tabnot.AskNmColumns(tabnote, nmColumns)
For ii As Integer = 0 To nmColumns - 1
Dim column As NXOpen.Tag
theUfSession.Tabnot.AskNthColumn(tabnote, 0, column)
theUfSession.Tabnot.RemoveColumn(column)
theUfSession.Obj.DeleteObject(column)
Next

' Now add our columns as needed
Dim columns(nColumns - 1) As NXOpen.Tag
For ii As Integer = 0 To nColumns - 1
theUfSession.Tabnot.CreateColumn(30, columns(ii))
theUfSession.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
'ufs.Tabnot.AskColumnWidth(columns(i), width)
'width = 0.75
theUfSession.Tabnot.SetColumnWidth(columns(ii), 50)
Next

' Now add our rows as needed
Dim rows(nRows - 1) As NXOpen.Tag
For ii As Integer = 0 To nRows - 1
theUfSession.Tabnot.CreateRow(30, rows(ii))
theUfSession.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)

Next
Return tabnote

Catch ex As NXOpen.NXException
lw.Open()
lw.WriteLine(ex.Message)

Catch ex As Exception
lw.Open()
lw.WriteLine(ex.GetBaseException.ToString())

End Try

End Function

Private Function ComparePointNames(ByVal x As String, ByVal y As String) As Integer

'case-insensitive sort
Dim myStringComp As StringComparer = StringComparer.CurrentCultureIgnoreCase

'for a case-sensitive sort (A-Z then a-z), change the above option to:
'Dim myStringComp As StringComparer = StringComparer.CurrentCulture

Return myStringComp.Compare(x, y)

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'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

The .CreateColumn method allows you to specify the column width at the time of creation. Your code uses this method in the CreateTabnoteWithSize function. You'll just need to keep track of which column you are adding and specify the width accordingly. I think there is a method to size the column after creation, but I can't find an example of that right now.

I know of no way to keep the table values associative to the points. If you come up with something, please post the solution.

hi NXJournaling, i have somehow managed to set different column width for the tabular note. As an addition to the existing journal, i have converted the coordinates from Global to my local coordinate. I used the journal from this below link to measure the distance between two coordinate systems.
http://www.nxjournaling.com/comment/4488#comment-4488
The journal i created is working fine except that, if i chose to keep the WCS the font size is getting changed and so as the decimals. I'am not sure where the code is going wrong. Could you please figure out the cause for this issue.

' NX 12.0.1.7
' Journal created by Balaji_Sampath03 on Mon Jun 29 20:50:40 2020 India Standard Time

'**************************************************************************************
'This Journal creates the co-ordinate point table for all visible drafting points in the view
'Corresponding Point Names are also inserted in the table
'Points are custom sorted before tabulating the co-ordinates
'Global Co-ordinate values are converted to Local axis co-ordinate values
'***************************************************************************************
Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module Tab_Coordinates

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim theUI As UI = UI.GetUI()
Dim theDraftView As Drawings.DraftingView
Dim ptsPoints As New List(Of Point)
Dim ptsNames As New List(Of String)
Dim viewName As String = Nothing
Dim ptsCount As Integer = "0"
Dim tempName As String = Nothing
Dim lw As ListingWindow = theSession.ListingWindow
Dim pName As String = Nothing

Sub Main (ByVal args() As String)

lw.Open()
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Co-Ordinates Table")

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel

viewName = theDraftView.Name

'Check for the points and points to list: Exit if there is no point
'------------------------------------------------------------------
For Each tempObj As DisplayableObject In theDraftView.AskVisibleObjects
If TypeOf tempObj Is Point Then
ptsPoints.Add(tempObj)
tempObj.Highlight
End If
Next

If ptsPoints.ToArray().Length = 0 Then
lw.Open()
lw.WriteLine("No Points found. Exit.")
Return
End If

'Get location for Co-ordinates Table
'-----------------------------------
Dim cursor As Point3d
Dim response As Selection.DialogResponse = SelectScreenPos(cursor)
If response <> Selection.DialogResponse.Pick Then
Return
End If

'Reverse String before Sort
'--------------------------
For i As Integer = 0 To ptsPoints.Count - 1
Dim fName As String = Nothing
Dim pName As String = Nothing
fName = ptsPoints.Item(i).Name
pName=StrReverse(fName)
ptsPoints.Item(i).SetName(pName)
Next

' Sort All point Names
'------------------------
ptsPoints.Sort(AddressOf ComparePointNames)
For Each tempObj as Point in ptsPoints
tempName =(tempObj.Name)
ptsNames.Add(tempName)
Next

'Reverse String After Sort
'--------------------------
For i As Integer = 0 To ptsPoints.Count - 1
Dim fName As String = Nothing
Dim pName As String = Nothing
fName = ptsPoints.Item(i).Name
pName=StrReverse(fName)
ptsPoints.Item(i).SetName(pName)
Next

' Create the tabular note
'------------------------
Dim n_new_columns As Integer = 5
Dim n_new_rows As Integer = 0
Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(n_new_rows, 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
theUfSession.Tabnot.AskNthColumn(tabnote, ii, columns(ii))
Next
Dim cell As NXOpen.Tag

' Add Title Row
'--------------
Dim TitleRow As Tag
Dim height As Double = Nothing

theUfSession.Tabnot.CreateRow(15, TitleRow)
theUfSession.Tabnot.AddRow(tabnote, TitleRow, UFConstants.UF_TABNOT_APPEND)

Dim cellprefes As UFTabnot.CellPrefs = Nothing

Dim cell1 As NXOpen.Tag
Dim cell2 As NXOpen.Tag
Dim cell3 As NXOpen.Tag
Dim cell4 As NXOpen.Tag
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(2), cell1)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(4), cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell3)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(1), cell4)
theUfSession.Tabnot.MergeCells(cell1, cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell1, "Koordinaten von Ebenen RX,RY,RZ Coordinates from Planes RX, RY, RZ")

' Add Header Row
'---------------
Dim headerrow As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, headerrow)
theUfSession.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)

theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, "Kontrollmass Check Dimension")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell)
theUfSession.Tabnot.SetCellText(cell, "Schnitt Section")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, "X")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, "Y")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, "Z")

Dim cell5 As NXOpen.Tag
Dim cell6 As NXOpen.Tag
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell5)
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell6)
theUfSession.Tabnot.MergeCells(cell3, cell5)
theUfSession.Tabnot.MergeCells(cell4, cell6)

'Convert from ABS to Selected CSYS
'-----------------------------------
Dim convABS2Local As Integer = theUI.NXMessageBox.Show("Select CSYS",
NXOpen.NXMessageBox.DialogType.Question, "Convert from 'ABS' to 'LocalCSYS'..?")

If convABS2Local = 1 Then

'------------------
' Set the cell text
'------------------

theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
workPart.Drafting.ExitDraftingApplication()

For Each comp As Component In theSession.Parts.Work.ComponentAssembly.RootComponent.GetChildren
Dim childCompName As String = comp.Name
Dim component1 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT "& childCompName &" 1"), NXOpen.Assemblies.Component)
Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
workPart = theSession.Parts.Work ' childCompName
partLoadStatus1.Dispose()
Next

Dim myStartObject As CoordinateSystem = theSession.Parts.Work.WCS.CoordinateSystem
Dim startPoint As Point3d = myStartObject.Origin
Dim startOrientation As NXMatrix = myStartObject.Orientation
Dim startCsys(8) As Double
'0-2 = origin point in abs coordinates
startCsys(0) = startPoint.X.ToString("F3")
startCsys(1) = startPoint.Y.ToString("F3")
startCsys(2) = startPoint.Z.ToString("F3")
'3-8 = X & Y vectors in abs coordinates
startCsys(3) = startOrientation.Element.Xx
startCsys(4) = startOrientation.Element.Xy
startCsys(5) = startOrientation.Element.Xz
startCsys(6) = startOrientation.Element.Yx
startCsys(7) = startOrientation.Element.Yy
startCsys(8) = startOrientation.Element.Yz
'NX derives the Z vector from the given X and Y vectors

Dim myEndObject As CoordinateSystem = Nothing
Dim foundEnd As Boolean = False

For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
If tempCsys.Name = "RDCS" Then
myEndObject = tempCsys
foundEnd = True
Exit For
End If
Next

If Not foundEnd Then
lw.WriteLine("RDCS not found")
Return
End If

Dim endPoint As Point3d = myEndObject.Origin
Dim endOrientation As NXMatrix = myEndObject.Orientation
Dim endCsys(8) As Double
'0-2 = origin point in abs coordinates
endCsys(0) = endPoint.X.ToString("F3")
endCsys(1) = endPoint.Y.ToString("F3")
endCsys(2) = endPoint.Z.ToString("F3")
'3-8 = X & Y vectors in abs coordinates
endCsys(3) = endOrientation.Element.Xx
endCsys(4) = endOrientation.Element.Xy
endCsys(5) = endOrientation.Element.Xz
endCsys(6) = endOrientation.Element.Yx
endCsys(7) = endOrientation.Element.Yy
endCsys(8) = endOrientation.Element.Yz
'NX derives the Z vector from the given X and Y vectors

Dim fromOrigin() As Double = {startPoint.X, startPoint.Y, startPoint.Z}
Dim fromXAxis() As Double = {startOrientation.Element.Xx, startOrientation.Element.Xy, startOrientation.Element.Xz}
Dim fromYAxis() As Double = {startOrientation.Element.Yx, startOrientation.Element.Yy, startOrientation.Element.Yz}

Dim toOrigin() As Double = {endPoint.X, endPoint.Y, endPoint.Z}
Dim toXAxis() As Double = {endOrientation.Element.Xx, endOrientation.Element.Xy, endOrientation.Element.Xz}
Dim toYAxis() As Double = {endOrientation.Element.Yx, endOrientation.Element.Yy, endOrientation.Element.Yz}

Dim mtx4Transform(15) As Double
theUfSession.Mtx4.CsysToCsys(fromOrigin, fromXAxis, fromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform)

Dim ordX, ordY, ordZ As String
ordX = (endPoint.X - startPoint.X).ToString("F3")
ordY = (endPoint.Y - startPoint.Y).ToString("F3")
ordZ = (endPoint.Z - startPoint.Z).ToString("F3")

Dim ordVal(2) As String

'-------------------------
' Add a row for each point
'-------------------------
For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3") - ordX
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3") - ordY
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3") - ordZ

Dim row As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, row)
theUfSession.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(row, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, StrReverse(ptsNames.Item(i)))

theUfSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(0))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(1))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(2))
Next

theSession.ApplicationSwitchImmediate("UG_APP_DRAFTING")
workPart.Drafting.EnterDraftingApplication()

Else

'-------------------------
' Add a row for each point
'-------------------------

Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing

For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1

Dim row As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, row)
theUfSession.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(row, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, StrReverse(ptsNames.Item(i)))
'theUfSession.Tabnot.SetCellText(cell, ptsNames.Item(i))

Dim ordVal(2) As String

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3")
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3")
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3")

theUfSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(0))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(1))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(2))
Next
End If

' Clear Points & Name List
'-------------------------
ptsPoints.Clear()
ptsNames.Clear()

'Clear Selection List
'--------------------

Dim partCleanup As NXOpen.PartCleanup = Nothing
partCleanup = theSession.NewPartCleanup()
partCleanup.TurnOffHighlighting = True
partCleanup.DoCleanup()
partCleanup.Dispose()

Loop

End Sub

Function SelDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a drafting view"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selView = CType(selObj, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse
Dim theUI As UI = UI.GetUI()
Dim view As NXOpen.View = Nothing
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Return theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)
End Function

Public Function CreateTabnoteWithSize(ByVal nRows As Integer,
ByVal nColumns As Integer,
ByVal loc As Point3d) As NXOpen.Tag

Try
' Create the tabular note
Dim secPrefs As UFTabnot.SectionPrefs
theUfSession.Tabnot.AskDefaultSectionPrefs(secPrefs)
Dim cellPrefs As UFTabnot.CellPrefs
theUfSession.Tabnot.AskDefaultCellPrefs(cellPrefs)
cellPrefs.zero_display = UFTabnot.ZeroDisplay.ZeroDisplayZero
cellPrefs.line_space_factor = 1.0
cellPrefs.nm_fit_methods = 1
'cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodAutoSizeRow
'cellPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodAutoSizeCol
cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodWrap
theUfSession.Tabnot.SetDefaultCellPrefs(cellPrefs)

Dim origin(2) As Double
origin(0) = loc.X
origin(1) = loc.Y
origin(2) = loc.Z
Dim tabnote As NXOpen.Tag
theUfSession.Tabnot.Create(secPrefs, origin, tabnote)

' Delete all existing columns and rows (we create them as needed)
Dim nmRows As Integer = 0
theUfSession.Tabnot.AskNmRows(tabnote, nmRows)
For ii As Integer = 0 To nmRows - 1
Dim row As NXOpen.Tag
theUfSession.Tabnot.AskNthRow(tabnote, 0, row)
theUfSession.Tabnot.RemoveRow(row)
theUfSession.Obj.DeleteObject(row)
Next

Dim nmColumns As Integer = 0
theUfSession.Tabnot.AskNmColumns(tabnote, nmColumns)
For ii As Integer = 0 To nmColumns - 1
Dim column As NXOpen.Tag
theUfSession.Tabnot.AskNthColumn(tabnote, 0, column)
theUfSession.Tabnot.RemoveColumn(column)
theUfSession.Obj.DeleteObject(column)
Next

' Now add our columns as needed
Dim columns(nColumns - 1) As NXOpen.Tag
For ii As Integer = 0 To nColumns - 1
Dim Width As Integer
theUfSession.Tabnot.CreateColumn(33, columns(ii))
theUfSession.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
'theUfSession.Tabnot.AskColumnWidth(columns(ii), width)
'width = 50
'theUfSession.Tabnot.SetColumnWidth(columns(ii), 50)
Next

For j As Integer = 0 To nColumns - 4
theUfSession.Tabnot.SetColumnWidth(columns(j), 50)
Next

For k As Integer = 1 To nColumns - 4
theUfSession.Tabnot.SetColumnWidth(columns(k), 25)
Next

' Now add our rows as needed
Dim rows(nRows - 1) As NXOpen.Tag
For ii As Integer = 0 To nRows - 1
theUfSession.Tabnot.CreateRow(8, rows(ii))
theUfSession.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)

Next
Return tabnote

Catch ex As NXOpen.NXException
lw.Open()
lw.WriteLine(ex.Message)

Catch ex As Exception
lw.Open()
lw.WriteLine(ex.GetBaseException.ToString())

End Try

End Function

Private Function ComparePointNames(ByVal x As Point, ByVal y As Point) As Integer

'case-insensitive sort
Dim myStringComp As StringComparer = StringComparer.CurrentCultureIgnoreCase

'for a case-sensitive sort (A-Z then a-z), change the above option to:
'Dim myStringComp As StringComparer = StringComparer.CurrentCulture

Return myStringComp.Compare(x.Name, y.Name)

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'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

Balaji

Hello NXJournaling, could you please help with the above journal. The font size and the decimals for the point coordinate values are not as desired when I convert the global to local coordinates system. However it is working fine if I don't convert the coordinate system. Thanks, B

Balaji

I created a quick test file with a few points and ran your journal. It runs fine when I do not convert to a local coordinate system, but when I do, it returns an error (object reference not set). In the case of converting the coordinates, it appears that the code is looking for components. I created an assembly and added the part with points as a component, but I get the same error. What type of structure is your journal expecting? If possible, please email a test file to info@nxjournaling.com

Hello NXJournaling, First things first.Thanks for your effort and reply. :) :)
I remember getting similar error if i don't set the WCS to Datum CSYS. I'm not sure though. My test file always has a drawing with just one component attached to it. (Separate drawing and part). Sure i will send a test file to your mail at the earliest. Thanks, B

Balaji

Hello NJournaling, even i was getting an error in line 176 when i tried to make a test file to send you.

Dim component1 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT "& childCompName &" 1"), NXOpen.Assemblies.Component)

I am trying to send another file to your mail, where the journal was working fine. AT the moment i have some issues attaching the files through my personal mail. May be 'cos i/m using my office computer and assessing personal mail.Will let you know once i've sent the files. Thanks, B

Balaji

Hello NXJournaling, I have sent the test files to your mail. Thanks, B

Balaji

I have a better understanding of what is going on now. The code tries to set a component as the work part and then access the WCS; NX will not allow this while the assembly is still the display part. The display part controls the WCS, you cannot access the work part's WCS (unless it is also set as the display part).

I can't reproduce the font issue with the new code, but this is what I think was happening: when ABS was chosen, the code ran normally; when WCS was chosen, it set the component as the work part and pulled the font preferences from the component part instead of the drawing part.

To get something up and running quickly, I went back to my original code and added your drafting view selection function and loop logic. Please test the results (coordinates) of the code below. If it is correct, you can incorporate the method into your own code.

Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities

Structure PointData
Public PointObj As Point
Public CoordsABS As Point3d
Public CoordsWCS As Point3d
End Structure

Module Module165

' Creates a tabular note with all Point coordinates from the chosen drafting view.
' Optionally, the coordinates are mapped to the current WCS of the drawing part.
' To get the WCS, the drawing display is turned off/on temporarily.

Dim theSession As Session = Session.GetSession()
Dim ufs As UFSession = UFSession.GetUFSession()
Dim theUI As UI = UI.GetUI()
Dim lw As ListingWindow = theSession.ListingWindow
Dim workPart As Part = theSession.Parts.Work

Sub Main()

Dim markId1 As Session.UndoMarkId
markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Point table")
lw.Open()

Dim ptList As List(Of PointData) = New List(Of PointData)
Dim theDraftView As Drawings.DraftingView
Dim viewName As String = Nothing

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel

viewName = theDraftView.Name

'Check for the points and points to list: Exit if there is no point
'------------------------------------------------------------------
Dim num_visible As Integer
Dim visible_objects() As Tag
Dim num_clipped As Integer
Dim clipped_objects() As Tag
ufs.View.AskVisibleObjects(theDraftView.Tag, num_visible, visible_objects, num_clipped, clipped_objects)
Dim visible_points As New List(Of Point)
For Each tempTag As Tag In visible_objects
Dim tempDispObj As DisplayableObject = Utilities.NXObjectManager.Get(tempTag)
If TypeOf (tempDispObj) Is Point Then
visible_points.Add(tempDispObj)
End If
Next

For Each tempPt As Point In visible_points
Dim pt As PointData
pt.PointObj = tempPt
pt.CoordsABS = tempPt.Coordinates
ptList.Add(pt)
Next

If ptList.Count = 0 Then
lw.WriteLine("No Points found. Exit.")
Return
End If

' Get a location for the tabular note
Dim cursor As Point3d
Dim response As Selection.DialogResponse = SelectScreenPos(cursor)
If response <> Selection.DialogResponse.Pick Then
Return
End If

' Ask to use ABS or WCS coordinates
Dim answer As Integer = theUI.NXMessageBox.Show("Coordinates",
NXOpen.NXMessageBox.DialogType.Question, "Convert ABS to WCS values?")
If answer = 1 Then
MapPointsFromAbsToWcs(ptList)
End If

'For Each pt As PointData In ptList
' lw.WriteLine(vbCrLf + "ABS: " + pt.CoordsABS.X.ToString() + " " + pt.CoordsABS.Y.ToString() + " " + pt.CoordsABS.Z.ToString())
' lw.WriteLine("WCS: " + pt.CoordsWCS.X.ToString() + " " + pt.CoordsWCS.Y.ToString() + " " + pt.CoordsWCS.Z.ToString())
'Next

' Create the tabular note
Dim n_new_columns As Integer = 4
Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(1, 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))
Next

Dim cell As NXOpen.Tag

' Add Title Row
Dim TitleRow As Tag
ufs.Tabnot.CreateRow(30, TitleRow)
ufs.Tabnot.AddRow(tabnote, TitleRow, UFConstants.UF_TABNOT_APPEND)
'Dim cellprefes As UFTabnot.CellPrefs = Nothing
Dim cell1 As NXOpen.Tag
ufs.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell1)
Dim cell2 As NXOpen.Tag
ufs.Tabnot.AskCellAtRowCol(TitleRow, columns(3), cell2)
ufs.Tabnot.MergeCells(cell1, cell2)
ufs.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell)
ufs.Tabnot.SetCellText(cell1, "XYZ POINTS")

' Add Header Row
Dim headerrow As NXOpen.Tag
ufs.Tabnot.CreateRow(30, headerrow)
ufs.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)

ufs.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
ufs.Tabnot.SetCellText(cell, "ID")
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 one row for each point
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Dim jj As Integer = 0

For Each pt As PointData In ptList
Dim id As Integer = jj + 1
Dim pt3dCoords As Point3d
If answer = 1 Then
' Use the Coordinates in WCS
pt3dCoords = pt.CoordsWCS
Else
' Use the Coordinates in ABS
pt3dCoords = pt.CoordsABS
End If

' Add a row for each point
Dim row As NXOpen.Tag
ufs.Tabnot.CreateRow(30, row)
ufs.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
ufs.Tabnot.AskCellAtRowCol(row, columns(0), cell)
ufs.Tabnot.SetCellText(cell, id.ToString())
' Set the cell text (pour ajuster le nombre de decimals changer la valeur "F")
ufs.Tabnot.AskCellAtRowCol(row, columns(1), cell)
ufs.Tabnot.SetCellText(cell, pt3dCoords.X.ToString("F3"))
ufs.Tabnot.AskCellAtRowCol(row, columns(2), cell)
ufs.Tabnot.SetCellText(cell, pt3dCoords.Y.ToString("F3"))
ufs.Tabnot.AskCellAtRowCol(row, columns(3), cell)
ufs.Tabnot.SetCellText(cell, pt3dCoords.Z.ToString("F3"))

' Add ID notes to the points
'AddNoteToPoint(id, pt.CoordsABS, theDraftView)

jj = jj + 1

Next

Loop

End Sub

Function SelDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a drafting view"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt,
title, scope, selAction,
includeFeatures, keepHighlighted, selectionMask_array,
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selView = CType(selObj, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Sub MapPointsFromAbsToWcs(ByRef ptList As List(Of PointData))

Dim module_id As Integer = 0
ufs.UF.AskApplicationModule(module_id)

'If we are in drafting, we need the modeling view to access WCS
If module_id = UFConstants.UF_APP_DRAFTING Then
ufs.Disp.SetDisplay(UFConstants.UF_DISP_SUPPRESS_DISPLAY)
ufs.Draw.SetDisplayState(1)
End If

For ii As Integer = 0 To ptList.Count - 1
Dim ptNew As PointData = ptList(ii)

Dim ptAbsVal As Double() = {ptNew.CoordsABS.X, ptNew.CoordsABS.Y, ptNew.CoordsABS.Z}
Dim ptWcsVal As Double() = New Double(2) {}
ufs.Csys.MapPoint(UFConstants.UF_CSYS_ROOT_COORDS, ptAbsVal,
UFConstants.UF_CSYS_ROOT_WCS_COORDS, ptWcsVal)

Dim ptWcs As Point3d = New Point3d(ptWcsVal(0), ptWcsVal(1), ptWcsVal(2))
ptNew.CoordsWCS = ptWcs
ptList(ii) = ptNew
Next

If module_id = UFConstants.UF_APP_DRAFTING Then
ufs.Disp.SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
ufs.Draw.SetDisplayState(2)
End If

ufs.Disp.RegenerateDisplay()

End Sub

Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse
Dim view As NXOpen.View = Nothing
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Return theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)
End Function

Public Function CreateTabnoteWithSize(ByVal nRows As Integer,
ByVal nColumns As Integer,
ByVal loc As Point3d) As NXOpen.Tag

Try
' Create the tabular note
Dim secPrefs As UFTabnot.SectionPrefs
ufs.Tabnot.AskDefaultSectionPrefs(secPrefs)
Dim cellPrefs As UFTabnot.CellPrefs
ufs.Tabnot.AskDefaultCellPrefs(cellPrefs)
cellPrefs.zero_display = UFTabnot.ZeroDisplay.ZeroDisplayZero
cellPrefs.line_space_factor = 1.0
cellPrefs.nm_fit_methods = 2
cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodAutoSizeRow
cellPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodAutoSizeCol
ufs.Tabnot.SetDefaultCellPrefs(cellPrefs)

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)
ufs.Tabnot.RemoveRow(row)
ufs.Obj.DeleteObject(row)
Next
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)
ufs.Tabnot.RemoveColumn(column)
ufs.Obj.DeleteObject(column)
Next

' Now add our columns as needed
Dim columns(nColumns - 1) As NXOpen.Tag
For ii As Integer = 0 To nColumns - 1
ufs.Tabnot.CreateColumn(30, columns(ii))
ufs.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
Next

' Now add our rows as needed
Dim rows(nRows - 1) As NXOpen.Tag
For ii As Integer = 0 To nRows - 1
ufs.Tabnot.CreateRow(30, rows(ii))
ufs.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)
Next

Return tabnote

Catch ex As NXOpen.NXException
lw.Open()
lw.WriteLine(ex.Message)

Catch ex As Exception
lw.Open()
lw.WriteLine(ex.GetBaseException.ToString())

End Try

End Function

Function AddNoteToPoint(ByVal id As Integer, ByVal pt As Point3d, ByVal dwgview As Drawings.BaseView)

Dim nullAnnotations_SimpleDraftingAid As Annotations.SimpleDraftingAid = Nothing
Dim draftingNoteBuilder1 As Annotations.DraftingNoteBuilder
draftingNoteBuilder1 = workPart.Annotations.CreateDraftingNoteBuilder(nullAnnotations_SimpleDraftingAid)
Dim text1(0) As String
text1(0) = id.ToString()
draftingNoteBuilder1.Text.TextBlock.SetText(text1)
draftingNoteBuilder1.Origin.AnnotationView.Value = dwgview
draftingNoteBuilder1.Origin.Origin.SetValue(Nothing, Nothing, pt)
draftingNoteBuilder1.Style.LetteringStyle.GeneralTextSize = 3.5
draftingNoteBuilder1.Commit()
draftingNoteBuilder1.Destroy()

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer
Return Session.LibraryUnloadOption.Immediately
End Function

End Module

Hello NXJournaling, Thanks for your explanation and the sample code. Your explanations made me understand what was happening.I tried running your test code. But the resulting coordinates were the same, irrespective of my selection of the ABS or the WCS. I've made small changes to my code from your sample code. Instead of going to the modeling mode from the drafting mode to access the WCS, i made a wavelink of the axis system of interest (WCS). Now the code is slightly better for the sample file which i have shared to your mail. Turns out that the fonts are coming fine, except that the issue with the decimal places are still there. I still don't understand this absurd behavior of the code. Below is by updated code. Could your please have a look. Thanks, B

Option Strict Off

Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.Annotations
Imports NXOpen.UI
Imports NXOpen.UF
Imports NXOpen.Utilities
Imports NXOpen.Assemblies

Module Tab_Coordinates

Dim theSession As Session = Session.GetSession()
Dim theUfSession As UFSession = UFSession.GetUFSession()
Dim workPart As Part = theSession.Parts.Work
Dim displayPart As Part = theSession.Parts.Display
Dim theUI As UI = UI.GetUI()
Dim theDraftView As Drawings.DraftingView
Dim ptsPoints As New List(Of Point)
Dim ptsNames As New List(Of String)
Dim viewName As String = Nothing
Dim ptsCount As Integer = "0"
Dim tempName As String = Nothing
Dim lw As ListingWindow = theSession.ListingWindow
Dim pName As String = Nothing

Sub Main (ByVal args() As String)

lw.Open()
Dim markId1 As NXOpen.Session.UndoMarkId = Nothing
markId1 = theSession.SetUndoMark(NXOpen.Session.MarkVisibility.Visible, "Co-Ordinates Table")

Do Until SelDraftingView("select drafting view", theDraftView) = Selection.Response.Cancel

viewName = theDraftView.Name

'Check for the points and points to list: Exit if there is no point
'------------------------------------------------------------------
For Each tempObj As DisplayableObject In theDraftView.AskVisibleObjects
If TypeOf tempObj Is Point Then
ptsPoints.Add(tempObj)
tempObj.Highlight
End If
Next

If ptsPoints.ToArray().Length = 0 Then
lw.Open()
lw.WriteLine("No Points found. Exit.")
Return
End If

'Get location for Co-ordinates Table
'-----------------------------------
Dim cursor As Point3d
Dim response As Selection.DialogResponse = SelectScreenPos(cursor)
If response <> Selection.DialogResponse.Pick Then
Return
End If

'Reverse String before Sort
'--------------------------
For i As Integer = 0 To ptsPoints.Count - 1
Dim fName As String = Nothing
Dim pName As String = Nothing
fName = ptsPoints.Item(i).Name
pName=StrReverse(fName)
ptsPoints.Item(i).SetName(pName)
Next

' Sort All point Names
'------------------------
ptsPoints.Sort(AddressOf ComparePointNames)
For Each tempObj as Point in ptsPoints
tempName =(tempObj.Name)
ptsNames.Add(tempName)
Next

'Reverse String After Sort
'--------------------------
For i As Integer = 0 To ptsPoints.Count - 1
Dim fName As String = Nothing
Dim pName As String = Nothing
fName = ptsPoints.Item(i).Name
pName=StrReverse(fName)
ptsPoints.Item(i).SetName(pName)
Next

' Create the tabular note
'------------------------
Dim n_new_columns As Integer = 5
Dim n_new_rows As Integer = 0
Dim tabnote As NXOpen.Tag = CreateTabnoteWithSize(n_new_rows, 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
theUfSession.Tabnot.AskNthColumn(tabnote, ii, columns(ii))
Next
Dim cell As NXOpen.Tag

' Add Title Row
'--------------
Dim TitleRow As Tag
Dim height As Double = Nothing

theUfSession.Tabnot.CreateRow(15, TitleRow)
theUfSession.Tabnot.AddRow(tabnote, TitleRow, UFConstants.UF_TABNOT_APPEND)

Dim cellprefes As UFTabnot.CellPrefs = Nothing

Dim cell1 As NXOpen.Tag
Dim cell2 As NXOpen.Tag
Dim cell3 As NXOpen.Tag
Dim cell4 As NXOpen.Tag
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(2), cell1)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(4), cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell3)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(1), cell4)
theUfSession.Tabnot.MergeCells(cell1, cell2)
theUfSession.Tabnot.AskCellAtRowCol(TitleRow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell1, "Koordinaten von Ebenen RX,RY,RZ Coordinates from Planes RX, RY, RZ")

' Add Header Row
'---------------
Dim headerrow As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, headerrow)
theUfSession.Tabnot.AddRow(tabnote, headerrow, UFConstants.UF_TABNOT_APPEND)

theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, "Kontrollmass Check Dimension")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell)
theUfSession.Tabnot.SetCellText(cell, "Schnitt Section")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, "X")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, "Y")
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, "Z")

Dim cell5 As NXOpen.Tag
Dim cell6 As NXOpen.Tag
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(0), cell5)
theUfSession.Tabnot.AskCellAtRowCol(headerrow, columns(1), cell6)
theUfSession.Tabnot.MergeCells(cell3, cell5)
theUfSession.Tabnot.MergeCells(cell4, cell6)

'Convert from ABS to Selected CSYS
'-----------------------------------
Dim convABS2Local As Integer = theUI.NXMessageBox.Show("Select CSYS",
NXOpen.NXMessageBox.DialogType.Question, "Convert from 'ABS' to 'LocalCSYS'..?")

If convABS2Local = 1 Then

'------------------
' Set the cell text
'------------------

'Dim letteringPrefs As LetteringPreferences = Nothing
'Dim userSymPrefs As UserSymbolPreferences = Nothing

Dim module_id As Integer = 0
theUfSession.UF.AskApplicationModule(module_id)

'If we are in drafting, we need the modeling view to access WCS
If module_id = UFConstants.UF_APP_DRAFTING Then
theUfSession.Disp.SetDisplay(UFConstants.UF_DISP_SUPPRESS_DISPLAY)
theUfSession.Draw.SetDisplayState(1)
End If

Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing

' theSession.ApplicationSwitchImmediate("UG_APP_MODELING")
' workPart.Drafting.ExitDraftingApplication()

' For Each comp As Component In theSession.Parts.Work.ComponentAssembly.RootComponent.GetChildren
' Dim childCompName As String = comp.Name
' Dim component1 As NXOpen.Assemblies.Component = CType(workPart.ComponentAssembly.RootComponent.FindObject("COMPONENT "& childCompName &" 1"), NXOpen.Assemblies.Component)
' Dim partLoadStatus1 As NXOpen.PartLoadStatus = Nothing
' theSession.Parts.SetWorkComponent(component1, NXOpen.PartCollection.RefsetOption.Entire, NXOpen.PartCollection.WorkComponentOption.Visible, partLoadStatus1)
' workPart = theSession.Parts.Work ' childCompName
' 'displayPart = theSession.Parts.Display ' childCompName
' partLoadStatus1.Dispose()
' Next

Dim myStartObject As CoordinateSystem = theSession.Parts.Work.WCS.CoordinateSystem
Dim startPoint As Point3d = myStartObject.Origin
Dim startOrientation As NXMatrix = myStartObject.Orientation
Dim startCsys(8) As Double
'0-2 = origin point in abs coordinates
startCsys(0) = startPoint.X.ToString("F3")
startCsys(1) = startPoint.Y.ToString("F3")
startCsys(2) = startPoint.Z.ToString("F3")
'3-8 = X & Y vectors in abs coordinates
startCsys(3) = startOrientation.Element.Xx
startCsys(4) = startOrientation.Element.Xy
startCsys(5) = startOrientation.Element.Xz
startCsys(6) = startOrientation.Element.Yx
startCsys(7) = startOrientation.Element.Yy
startCsys(8) = startOrientation.Element.Yz
'NX derives the Z vector from the given X and Y vectors

Dim myEndObject As CoordinateSystem = Nothing
Dim foundEnd As Boolean = False

For Each tempCsys As CoordinateSystem In workPart.CoordinateSystems
If tempCsys.Name = "RDCS" Then
myEndObject = tempCsys
foundEnd = True
Exit For
End If
Next

If Not foundEnd Then
lw.WriteLine("RDCS not found")
Return
End If

Dim endPoint As Point3d = myEndObject.Origin
Dim endOrientation As NXMatrix = myEndObject.Orientation
Dim endCsys(8) As Double
'0-2 = origin point in abs coordinates
endCsys(0) = endPoint.X.ToString("F3")
endCsys(1) = endPoint.Y.ToString("F3")
endCsys(2) = endPoint.Z.ToString("F3")
'3-8 = X & Y vectors in abs coordinates
endCsys(3) = endOrientation.Element.Xx
endCsys(4) = endOrientation.Element.Xy
endCsys(5) = endOrientation.Element.Xz
endCsys(6) = endOrientation.Element.Yx
endCsys(7) = endOrientation.Element.Yy
endCsys(8) = endOrientation.Element.Yz
'NX derives the Z vector from the given X and Y vectors

Dim fromOrigin() As Double = {startPoint.X, startPoint.Y, startPoint.Z}
Dim fromXAxis() As Double = {startOrientation.Element.Xx, startOrientation.Element.Xy, startOrientation.Element.Xz}
Dim fromYAxis() As Double = {startOrientation.Element.Yx, startOrientation.Element.Yy, startOrientation.Element.Yz}

Dim toOrigin() As Double = {endPoint.X, endPoint.Y, endPoint.Z}
Dim toXAxis() As Double = {endOrientation.Element.Xx, endOrientation.Element.Xy, endOrientation.Element.Xz}
Dim toYAxis() As Double = {endOrientation.Element.Yx, endOrientation.Element.Yy, endOrientation.Element.Yz}

Dim mtx4Transform(15) As Double
theUfSession.Mtx4.CsysToCsys(fromOrigin, fromXAxis, fromYAxis, toOrigin, toXAxis, toYAxis, mtx4Transform)

Dim ordX, ordY, ordZ As String
ordX = (endPoint.X - startPoint.X).ToString("F3")
ordY = (endPoint.Y - startPoint.Y).ToString("F3")
ordZ = (endPoint.Z - startPoint.Z).ToString("F3")

Dim ordVal(2) As String

'-------------------------
' Add a row for each point
'-------------------------
For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3") - ordX
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3") - ordY
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3") - ordZ

Dim row As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, row)
theUfSession.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(row, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, StrReverse(ptsNames.Item(i)))

theUfSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(0))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(1))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(2))
Next

If module_id = UFConstants.UF_APP_DRAFTING Then
theUfSession.Disp.SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
theUfSession.Draw.SetDisplayState(2)
End If

theUfSession.Disp.RegenerateDisplay()

'theSession.ApplicationSwitchImmediate("UG_APP_DRAFTING")
'workPart.Drafting.EnterDraftingApplication()

Else

'-------------------------
' Add a row for each point
'-------------------------

Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing

For i As Integer = 0 to ptsPoints.Count -1
ptsCount += 1

Dim row As NXOpen.Tag
theUfSession.Tabnot.CreateRow(8, row)
theUfSession.Tabnot.AddRow(tabnote, row, UFConstants.UF_TABNOT_APPEND)
theUfSession.Tabnot.AskCellAtRowCol(row, columns(0), cell)
theUfSession.Tabnot.SetCellText(cell, StrReverse(ptsNames.Item(i)))
'theUfSession.Tabnot.SetCellText(cell, ptsNames.Item(i))

Dim ordVal(2) As String

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3")
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3")
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3")

theUfSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(0))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(3), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(1))
theUfSession.Tabnot.AskCellAtRowCol(row, columns(4), cell)
theUfSession.Tabnot.SetCellText(cell, ordVal(2))
Next
End If

' Clear Points & Name List
'-------------------------
ptsPoints.Clear()
ptsNames.Clear()

'Clear Selection List
'--------------------

Dim partCleanup As NXOpen.PartCleanup = Nothing
partCleanup = theSession.NewPartCleanup()
partCleanup.TurnOffHighlighting = True
partCleanup.DoCleanup()
partCleanup.Dispose()

Loop

End Sub

Function SelDraftingView(ByVal prompt As String, ByRef selView As Drawings.DraftingView) As Selection.Response

Dim theUI As UI = UI.GetUI
Dim title As String = "Select a drafting view"
Dim includeFeatures As Boolean = False
Dim keepHighlighted As Boolean = False
Dim selAction As Selection.SelectionAction = Selection.SelectionAction.ClearAndEnableSpecific
Dim cursor As Point3d
Dim scope As Selection.SelectionScope = Selection.SelectionScope.WorkPart
Dim selectionMask_array(0) As Selection.MaskTriple
Dim selObj As TaggedObject

With selectionMask_array(0)
.Type = UFConstants.UF_view_type
.Subtype = UFConstants.UF_all_subtype
End With

Dim resp As Selection.Response = theUI.SelectionManager.SelectTaggedObject(prompt, _
title, scope, selAction, _
includeFeatures, keepHighlighted, selectionMask_array, _
selObj, cursor)
If resp = Selection.Response.ObjectSelected OrElse resp = Selection.Response.ObjectSelectedByName Then
selView = CType(selObj, Drawings.DraftingView)
Return Selection.Response.Ok
Else
Return Selection.Response.Cancel
End If

End Function

Public Function SelectScreenPos(ByRef pos As Point3d) As Selection.DialogResponse
Dim theUI As UI = UI.GetUI()
Dim view As NXOpen.View = Nothing
Dim letteringPrefs As LetteringPreferences = Nothing
Dim userSymPrefs As UserSymbolPreferences = Nothing
Return theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)
End Function

Public Function CreateTabnoteWithSize(ByVal nRows As Integer,
ByVal nColumns As Integer,
ByVal loc As Point3d) As NXOpen.Tag

Try
' Create the tabular note
Dim secPrefs As UFTabnot.SectionPrefs
theUfSession.Tabnot.AskDefaultSectionPrefs(secPrefs)
Dim cellPrefs As UFTabnot.CellPrefs
theUfSession.Tabnot.AskDefaultCellPrefs(cellPrefs)
cellPrefs.zero_display = UFTabnot.ZeroDisplay.ZeroDisplayZero
cellPrefs.line_space_factor = 1.0
cellPrefs.nm_fit_methods = 1
'cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodAutoSizeRow
'cellPrefs.fit_methods(1) = UFTabnot.FitMethod.FitMethodAutoSizeCol
cellPrefs.fit_methods(0) = UFTabnot.FitMethod.FitMethodWrap
theUfSession.Tabnot.SetDefaultCellPrefs(cellPrefs)

Dim origin(2) As Double
origin(0) = loc.X
origin(1) = loc.Y
origin(2) = loc.Z
Dim tabnote As NXOpen.Tag
theUfSession.Tabnot.Create(secPrefs, origin, tabnote)

' Delete all existing columns and rows (we create them as needed)
Dim nmRows As Integer = 0
theUfSession.Tabnot.AskNmRows(tabnote, nmRows)
For ii As Integer = 0 To nmRows - 1
Dim row As NXOpen.Tag
theUfSession.Tabnot.AskNthRow(tabnote, 0, row)
theUfSession.Tabnot.RemoveRow(row)
theUfSession.Obj.DeleteObject(row)
Next

Dim nmColumns As Integer = 0
theUfSession.Tabnot.AskNmColumns(tabnote, nmColumns)
For ii As Integer = 0 To nmColumns - 1
Dim column As NXOpen.Tag
theUfSession.Tabnot.AskNthColumn(tabnote, 0, column)
theUfSession.Tabnot.RemoveColumn(column)
theUfSession.Obj.DeleteObject(column)
Next

' Now add our columns as needed
Dim columns(nColumns - 1) As NXOpen.Tag
For ii As Integer = 0 To nColumns - 1
Dim Width As Integer
theUfSession.Tabnot.CreateColumn(33, columns(ii))
theUfSession.Tabnot.AddColumn(tabnote, columns(ii), UFConstants.UF_TABNOT_APPEND)
'theUfSession.Tabnot.AskColumnWidth(columns(ii), width)
'width = 50
'theUfSession.Tabnot.SetColumnWidth(columns(ii), 50)
Next

For j As Integer = 0 To nColumns - 4
theUfSession.Tabnot.SetColumnWidth(columns(j), 50)
Next

For k As Integer = 1 To nColumns - 4
theUfSession.Tabnot.SetColumnWidth(columns(k), 25)
Next

' Now add our rows as needed
Dim rows(nRows - 1) As NXOpen.Tag
For ii As Integer = 0 To nRows - 1
theUfSession.Tabnot.CreateRow(8, rows(ii))
theUfSession.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND)

Next
Return tabnote

Catch ex As NXOpen.NXException
lw.Open()
lw.WriteLine(ex.Message)

Catch ex As Exception
lw.Open()
lw.WriteLine(ex.GetBaseException.ToString())

End Try

End Function

Private Function ComparePointNames(ByVal x As Point, ByVal y As Point) As Integer

'case-insensitive sort
Dim myStringComp As StringComparer = StringComparer.CurrentCultureIgnoreCase

'for a case-sensitive sort (A-Z then a-z), change the above option to:
'Dim myStringComp As StringComparer = StringComparer.CurrentCulture

Return myStringComp.Compare(x.Name, y.Name)

End Function

Public Function GetUnloadOption(ByVal dummy As String) As Integer

'Unloads the image when the NX session terminates
'GetUnloadOption = NXOpen.Session.LibraryUnloadOption.AtTermination

'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

Balaji

Note that for my example code to work, you will need to move the WCS (in the drawing file) before running the journal for it to work. The part, as saved, has the WCS positioned at the ABS. Also, don't confuse the WCS with a datum csys feature or csys object; they are different things. There is only one WCS in the part.

I'll take a look at your updated code as time allows.

Hello NXJournaling, Thanks for your quick response. Now I understand how your code works. I made the axis system of my interest as the WCS and your code runs fine for my part (earlier i set the WCS at the ABS). Everything makes sense now and I have a better understanding. Thanks again for your explanation. I will try to impart your method into my code and try running it. Thanks, B

Balaji

Your code rounds values (by converting them to strings) then does more math with the rounded values then writes the result to the table. I'd suggest not rounding any values until you write the result to the table. This will help to minimize rounding errors and can make the code slightly faster (as it won't need to convert values to/from strings). I'm not sure, but it might also solve your 'number of decimal places' issue.

Current code:

Dim ordX, ordY, ordZ As String
ordX = (endPoint.X - startPoint.X).ToString("F3")
ordY = (endPoint.Y - startPoint.Y).ToString("F3")
ordZ = (endPoint.Z - startPoint.Z).ToString("F3")

Dim ordVal(2) As String

For i As Integer = 0 To ptsPoints.Count - 1
ptsCount += 1

ordVal(0) = ptsPoints(i).Coordinates.X.ToString("F3") - ordX
ordVal(1) = ptsPoints(i).Coordinates.Y.ToString("F3") - ordY
ordVal(2) = ptsPoints(i).Coordinates.Z.ToString("F3") - ordZ

theUFSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUFSession.Tabnot.SetCellText(cell, ordVal(0))

Updated code:

Dim ordX, ordY, ordZ As double
ordX = endPoint.X - startPoint.X
ordY = endPoint.Y - startPoint.Y
ordZ = endPoint.Z - startPoint.Z

Dim ordVal(2) As double

For i As Integer = 0 To ptsPoints.Count - 1
ptsCount += 1

ordVal(0) = ptsPoints(i).Coordinates.X - ordX
ordVal(1) = ptsPoints(i).Coordinates.Y - ordY
ordVal(2) = ptsPoints(i).Coordinates.Z. - ordZ

theUFSession.Tabnot.AskCellAtRowCol(row, columns(2), cell)
theUFSession.Tabnot.SetCellText(cell, ordVal(0).ToString("F3"))

Hello NXJournlaing, You nailed it..!!! I updated the code and it's giving the results as i expected. It's the issue with rounding of the values several times and conversion. And the issue with the fonts is also because of trying to access the coordinate system by entering into modeling application. Now, everything is clear and the code works fine with your updates. Thanks, B

Balaji