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.GenericImports NXOpen Imports NXOpen.AnnotationsImports NXOpen.UIImports NXOpen.UFImports NXOpen.UtilitiesImports System.Linq Module Tab_Coordinates Dim theSession As Session = Session.GetSession()Dim theUfSession As UFSession = UFSession.GetUFSession()Dim workPart As Part = theSession.Parts.WorkDim theUI As UI = UI.GetUI()'Dim displayPart As Part = theSession.Parts.DisplayDim theDraftView As Drawings.DraftingViewDim ptsPoints AsNew List(Of Point)Dim ptsNames AsNew List(OfString)Dim revNames AsNew List(OfString)Dim viewName AsString=NothingDim ptsCount AsInteger="0"Dim tempName AsString=NothingDim lw As ListingWindow = theSession.ListingWindow Sub Main (ByVal args()AsString) 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'------------------------------------------------------------------ForEach tempObj As DisplayableObject In theDraftView.AskVisibleObjectsIfTypeOf tempObj Is Point Then ptsPoints.Add(tempObj) tempObj.HighlightEndIfNext If ptsPoints.ToArray().Length=0Then lw.Open() lw.WriteLine("No Points found. Exit.")ReturnEndIf 'Get location for Co-ordinates Table'-----------------------------------Dim cursor As Point3d Dim response As Selection.DialogResponse= SelectScreenPos(cursor)If response <> Selection.DialogResponse.PickThenReturnEndIf 'Reverse String before Sort'--------------------------ForEach 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 155Dim revName AsString=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 AsInteger=5Dim n_new_rows AsInteger=0Dim tabnote As NXOpen.Tag= CreateTabnoteWithSize(n_new_rows, n_new_columns, cursor) ' Get the column tags'--------------------Dim columns(n_new_columns -1)As NXOpen.TagFor ii AsInteger=0To n_new_columns -1 theUfSession.Tabnot.AskNthColumn(tabnote, ii, columns(ii))NextDim cell As NXOpen.Tag ' Add Title Row'--------------Dim TitleRow As Tag Dim height AsDouble=NothingDim cellprefes As UFTabnot.CellPrefs=NothingDim cell1 As NXOpen.TagDim cell2 As NXOpen.TagDim cell3 As NXOpen.TagDim 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.TagDim cell5 As NXOpen.TagDim 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 =NothingDim userSymPrefs As UserSymbolPreferences =Nothing For i AsInteger=0to 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)AsString 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 EndSub Function SelDraftingView(ByVal prompt AsString, ByRef selView As Drawings.DraftingView)As Selection.Response Dim theUI As UI = UI.GetUIDim title AsString="Select a drafting view"Dim includeFeatures AsBoolean=FalseDim keepHighlighted AsBoolean=FalseDim selAction As Selection.SelectionAction= Selection.SelectionAction.ClearAndEnableSpecificDim cursor As Point3d Dim scope As Selection.SelectionScope= Selection.SelectionScope.WorkPartDim selectionMask_array(0)As Selection.MaskTripleDim selObj As TaggedObject With selectionMask_array(0).Type= UFConstants.UF_view_type.Subtype= UFConstants.UF_all_subtypeEndWith Dim resp As Selection.Response= theUI.SelectionManager.SelectTaggedObject(prompt, _ title, scope, selAction, _ includeFeatures, keepHighlighted, selectionMask_array, _ selObj, cursor)If resp = Selection.Response.ObjectSelectedOrElse resp = Selection.Response.ObjectSelectedByNameThen selView =CType(selObj, Drawings.DraftingView)Return Selection.Response.OkElseReturn Selection.Response.CancelEndIf EndFunction PublicFunction SelectScreenPos(ByRef pos As Point3d)As Selection.DialogResponseDim theUI As UI = UI.GetUI()Dim view As NXOpen.View=NothingDim letteringPrefs As LetteringPreferences =NothingDim userSymPrefs As UserSymbolPreferences =NothingReturn theUI.SelectionManager.SelectScreenPosition("Select location for tabnote", view, pos)EndFunction PublicFunction CreateTabnoteWithSize(ByVal nRows AsInteger, ByVal nColumns AsInteger, ByVal loc As Point3d)As NXOpen.Tag Try' Create the tabular noteDim 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)AsDouble origin(0)= loc.X origin(1)= loc.Y origin(2)= loc.ZDim tabnote As NXOpen.Tag theUfSession.Tabnot.Create(secPrefs, origin, tabnote) ' Delete all existing columns and rows (we create them as needed)Dim nmRows AsInteger=0 theUfSession.Tabnot.AskNmRows(tabnote, nmRows)For ii AsInteger=0To nmRows -1Dim row As NXOpen.Tag theUfSession.Tabnot.AskNthRow(tabnote, 0, row) theUfSession.Tabnot.RemoveRow(row) theUfSession.Obj.DeleteObject(row)Next Dim nmColumns AsInteger=0 theUfSession.Tabnot.AskNmColumns(tabnote, nmColumns)For ii AsInteger=0To nmColumns -1Dim column As NXOpen.Tag theUfSession.Tabnot.AskNthColumn(tabnote, 0, column) theUfSession.Tabnot.RemoveColumn(column) theUfSession.Obj.DeleteObject(column)Next ' Now add our columns as neededDim columns(nColumns -1)As NXOpen.TagFor ii AsInteger=0To 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 neededDim rows(nRows -1)As NXOpen.TagFor ii AsInteger=0To nRows -1 theUfSession.Tabnot.CreateRow(30, rows(ii)) theUfSession.Tabnot.AddRow(tabnote, rows(ii), UFConstants.UF_TABNOT_APPEND) NextReturn tabnote Catch ex As NXOpen.NXException lw.Open() lw.WriteLine(ex.Message) Catch ex As Exception lw.Open() lw.WriteLine(ex.GetBaseException.ToString()) EndTry EndFunction PrivateFunction ComparePointNames(ByVal x AsString, ByVal y AsString)AsInteger 'case-insensitive sortDim 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) EndFunction PublicFunction GetUnloadOption(ByVal dummy AsString)AsInteger '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 EndFunction EndModule