Exporting a Tabular Note by Row

Is it possible for a journal to find every tabular note on a drawing sheet and then export it by row to the listing window? I haven't found a tabular note collector and my recorded journals are coming up blank.

What you need to find are "tabular note sections"; the code below finds (and deletes) tabular notes from layer 256. You'll probably want to modify it a bit before running it :) but it does illustrate one way to cycle through and find tabular notes. Hopefully a future version will add a tabular note collection to make this easier...

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
 
Module Module2
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work
 
    Sub Main()
 
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()
 
        lw.WriteLine(workPart.FullPath)
 
        'create list of layer numbers to delete tabular notes from
        Dim tabularNoteLayerList As New List(Of Integer)
        tabularNoteLayerList.Add(256)
 
        'call sub to delete tabular notes
        DeleteTabularNotes(tabularNoteLayerList)
 
 
    End Sub
 
    Sub DeleteTabularNotes(ByVal layerList As List(Of Integer))
 
        Dim myTabNotes As New List(Of Annotations.TableSection)
        Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
        Dim myTabNote As NXOpen.Annotations.TableSection
        Dim type As Integer
        Dim subtype As Integer
 
        Do
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
            If tmpTabNote = NXOpen.Tag.Null Then
                Continue Do
            End If
            If tmpTabNote <> NXOpen.Tag.Null Then
                theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, type, subtype)
                If subtype = UFConstants.UF_tabular_note_section_subtype Then
                    myTabNote = (Utilities.NXObjectManager.Get(tmpTabNote))
 
                    If layerList.Contains(myTabNote.Layer) Then
                        myTabNotes.Add(myTabNote)
                    End If
 
                End If
            End If
        Loop Until tmpTabNote = NXOpen.Tag.Null
 
        Dim markId1 As Session.UndoMarkId
        markId1 = theSession.SetUndoMark(Session.MarkVisibility.Visible, "Delete Tables")
 
        Dim nErrs1 As Integer
        nErrs1 = theSession.UpdateManager.AddToDeleteList(myTabNotes.ToArray)
 
        Dim nErrs2 As Integer
        nErrs2 = theSession.UpdateManager.DoUpdate(markId1)
 
    End Sub
 
End Module

I can't find Annotations.TableSection. I am guessing it is something in NX 8 or later? I am still on 7.5.

Yes, it appears that the TableSection class is new to NX8. However, it isn't necessary for your task. Once you have the tag of the tabular note, you can use the functions in the UFTabnot class to query and modify it as you see fit.

Below is some code to write out info about the first tabular note found. It doesn't look for merged cells, not sure what it will report if one or more merged cells exist in the tabular note. I'll have to experiment with merged cells later...

Also, if you are exporting your notes to the listing window, be aware that there is a line length limit in the listing window (132 characters, I think). Long notes may wrap around to the next line; if this is unacceptable, you might try exporting the notes to a text file.

Option Strict Off
Imports System
Imports System.Collections.Generic
Imports NXOpen
Imports NXOpen.UF
 
Module export_tabular_notes
 
    Dim theSession As Session = Session.GetSession()
    Dim theUfSession As UFSession = UFSession.GetUFSession()
    Dim workPart As Part = theSession.Parts.Work
 
    Sub Main()
 
        Dim lw As ListingWindow = theSession.ListingWindow
        lw.Open()
 
        Dim myTabNotes As New List(Of Tag)
        FindTabularNotes(myTabNotes)
 
        lw.WriteLine("Number of tabular notes found: " & myTabNotes.Count.ToString)
        lw.WriteLine("")
 
        lw.WriteLine("First tabular note info:")
        lw.WriteLine("")
 
        Dim numSections As Integer = 0
        theUfSession.Tabnot.AskNmSections(myTabNotes.Item(0), numSections)
        lw.WriteLine("Number of sections in tabular note: " & numSections.ToString)
 
        Dim numRows As Integer = 0
        theUfSession.Tabnot.AskNmRows(myTabNotes.Item(0), numRows)
        lw.WriteLine("Number of rows in tabular note: " & numRows.ToString)
 
        Dim numCols As Integer = 0
        theUfSession.Tabnot.AskNmColumns(myTabNotes.Item(0), numCols)
        lw.WriteLine("Number of columns in tabular note: " & numCols.ToString)
        lw.WriteLine("")
 
        Dim rowTag As Tag = Nothing
        Dim colTag As Tag = Nothing
        Dim cellTag As Tag = Nothing
 
        For j As Integer = 0 To numRows - 1
 
            theUfSession.Tabnot.AskNthRow(myTabNotes.Item(0), j, rowTag)
 
            For k As Integer = 0 To numCols - 1
 
                theUfSession.Tabnot.AskNthColumn(myTabNotes.Item(0), k, colTag)
                theUfSession.Tabnot.AskCellAtRowCol(rowTag, colTag, cellTag)
                Dim cellText As String = ""
                Dim evalCellText As String = ""
                theUfSession.Tabnot.AskCellText(cellTag, cellText)
                theUfSession.Tabnot.AskEvaluatedCellText(cellTag, evalCellText)
 
                lw.WriteLine("Cell[" & j.ToString & "," & k.ToString & "]")
                lw.WriteLine("text: ")
                lw.WriteLine(cellText)
                lw.WriteLine("evaluated text: ")
                lw.WriteLine(evalCellText)
                lw.WriteLine("")
 
            Next
        Next
 
    End Sub
 
 
    Sub FindTabularNotes(ByRef tagList As List(Of Tag))
 
        Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
        Dim NxType As Integer
        Dim NxSubtype As Integer
 
        Do
            theUfSession.Obj.CycleObjsInPart(workPart.Tag, UFConstants.UF_tabular_note_type, tmpTabNote)
            If tmpTabNote <> NXOpen.Tag.Null Then
                theUfSession.Obj.AskTypeAndSubtype(tmpTabNote, NxType, NxSubtype)
                If NxSubtype = UFConstants.UF_tabular_note_subtype Then
                    tagList.Add(tmpTabNote) 
                End If
            End If
        Loop Until tmpTabNote = NXOpen.Tag.Null
 
    End Sub 
 
End Module

Hey,

I have a stupid question about the FindTabularNotes sub. What does that first if statement do? I see that it is cycling the objects in the part, but that first statement just seems to tell it to keep running if the tag is set to null. Couldnt you eclude that statement or am I missing something (I probably am tbh)

Also, and I right in thinking that it will end this do loop when it is set to null again, and that will happen wither if its run out of tabulare notes or if the part never had any to begin with?

The short answer is that, in this case, the If block can be removed without any ill consequences. I had copied some similar code and modified it for this purpose and didn't optimize this sub.

Passing in a null tag tells the cycle function to start from the beginning. If it returns a non-null tag, we pass that in on the next iteration and it will return the next object in the collection. When it runs out of objects, it will return a null tag.

Thank you! I think I'm beginning to understand. I have one more question, which may or may not be easy. How can I limit the layers I have the function search through? Is there a way to tell the cycleobjectsinpart to do only certain layers in its search?

The "DeleteTabularNotes" sub in the first code listing above shows how to get a tabular note object from its tag and check its layer.

I came back here to thank you and found out you had replied back later with code. After your comment about not actually needing the tablesection I went to work myself and came up with a solution that looks a lot like yours except my do loop to find all the tabular notes is in the main and my reading of the lines happens in a sub. It does seem to work fine merged cells. I did have to toss in "cell_text.Replace(vbCr, "::").Replace(vbLf, "::")" due to there being cases where multiple lines of text existed in a single cell.