Submitted by jelrae_farsun on Fri, 11/18/2016 - 02:10
Forums:
Im trying to get something that will collect all the tables from a specific layer/sheet. I want to then search through them for specific tables and then export specific information from the tables. I have an idea for how to search through the tables and export specific information from it, but I haven't been able to figure out how to get access to the tables to begin with. I have found I can use GetAllObjectsOnLayer to get all the objects, but I cannot figure out how to get the tables specifically out of that, or how to go through that data. Any idea?
re: tables on layer
The "DeleteTabularNotes" sub in the following link shows how to check the subtype, get a tabular note object given its tag, and use the object to check its layer.
http://nxjournaling.com/content/exporting-tabular-note-row
Still no dice
I tried this bit of code, which seemed to be checking the subtype, but im still getting that same error
If subtype = UFConstants.UF_tabular_note_section_subtype Then
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
Dim type As Integer
Dim subtype As Integer
Dim labelTables As New List(Of Tag)
For z As Integer = 0 To myTabNotes.Count - 1
theUfSession.Obj.AskTypeAndSubtype(myTabNotes(z), type, subtype)
If subtype = UFConstants.UF_tabular_note_section_subtype Then
lw.WriteLine(z) 'for testing purposes
'lw.WriteLine(myTabNotes.Item(0).GetType.string)
theUfSession.Tabnot.AskNthRow(myTabNotes.Item(z), 0, rowTag)
theUfSession.Tabnot.AskNthColumn(myTabNotes.Item(z), 0, 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)
if cellText = "IMPLANT COMPONENTS" Then
labelTables.Add(myTabNotes.Item(z))
End If
End If
Next
End Sub
Sub FindTabularNotes(ByRef tagList As List(Of Tag))
Dim tmpTabNote As NXOpen.Tag = NXOpen.Tag.Null
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
tagList.Add(tmpTabNote)
End If
Loop Until tmpTabNote = NXOpen.Tag.Null
End Sub
End Module
re: find tables
The subtype check should be done in the "FindTabularNote" subroutine. The original code in the link above was put together rather quickly and not fully tested; I've edited the code in the previous post to be better behaved. Please copy and paste the "FindTabularNote" code and try it again.
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