Hello, I am trying to print a very large table in NX using journaling. NX prints a very similar table (which I am trying to also build, but with a different format). The reason why I need to build it differently is that NX does not fetch all the pertinent information or organize it as we like.
I have everything figured out (in terms of actually building the table), but there seems to be a serious bottleneck that I cannot track down. To create a table with 250 rows by 13 columns, NX can produce the table in just over a minute. However, when I try to build the same table, it takes about 15 minutes!
I noticed that with every row I add, the cells get filled in slower, and slower, and slower. It feels like there's a memory buildup issue, even though my system resources are fine. Should I find a way to flush object memory? Or is this an issue with NX tabular notes? Below is the function I made to fetch data from a dictionary of objects and write them to a new row. I can post more code to provide additional context as needed.
Public Function RowPopulate(ByVal tabnote As NXOpen.Tag, ByVal columns() As NXOpen.Tag)
Dim TitleS(12) As String
Dim cell As NXOpen.Tag
For Each varKey In WireDictionary.Keys()
Dim IndWire As XWire = WireDictionary(varKey)
TitleS = {IndWire.WireName, IndWire.FromConnector, IndWire.FromPin, IndWire.FromTerminator,
"", IndWire.ToConnector, IndWire.ToPin, IndWire.ToTerminator, "", IndWire.WireSize, IndWire.Type & " - " & IndWire.Color,
IndWire.HYGSpec, IndWire.Spool}
Dim DataRow1 As New Tag
ufs.Tabnot.CreateRow(10, DataRow1)
ufs.Tabnot.AddRow(tabnote, DataRow1, UFConstants.UF_TABNOT_APPEND)
For i = 0 To 12
ufs.Tabnot.AskCellAtRowCol(DataRow1, columns(i), cell)
Try
ufs.Tabnot.SetCellText(cell, TitleS(i))
Catch ex As Exception
End Try
Next
Next
End Function
re: tabular note
I've not tested it, but I suspect the process of creating rows and appending them in a loop is what is slowing you down. If you have all of your information in a dictionary object before creating the tabular note, I suggest creating an empty tabular note large enough to hold the info. Now you can iterate through the dictionary and fill in existing cells in the note.
Empty Tabular Note of Proper Size
How do I use UFTabnot.SectionPrefs or UFTabnot.CellPrefs to set the initial rows/columns that are in a table upon creation? I know I'll need 13 columns and 250 rows for this specific example. But I realize I can do Dictionary.Count for the number of rows.
re: empty tabular note
I recorded a journal while creating a tabular note and it uses a TableSectionBuilder object to set the number of rows and columns (and other options) for the tabular note. Recorded code could be cleaned up and tweaked for your application.
Here is the recorded code
Here is the recorded code that I converted into a function. Everything works up until I try to grab the tag of the commited object. When I try to call a UF.Tabnot. Method, I get this error "Tag passed to function is not of a tabular note (UF_tabular_note_type) entity"
I tried researching other forum posts and found warnings of subtypes not being correct... but the code shows only one object commited. Is there a way of converting the tag that I'm not seeing?
Public Function NXCreateTable(ByVal nRows As Integer, ByVal nColumns As Integer, ByVal OriginP As Point3d) As NXOpen.Tag
Dim nullNXOpen_Annotations_TableSection As NXOpen.Annotations.TableSection = Nothing
Dim tableSectionBuilder1 As NXOpen.Annotations.TableSectionBuilder = Nothing
Dim table_finally As NXOpen.Annotations.TableSection
tableSectionBuilder1 = workPart.Annotations.TableSections.CreateTableSectionBuilder(nullNXOpen_Annotations_TableSection)
tableSectionBuilder1.RowHeight = 10.0
tableSectionBuilder1.NumberOfColumns = nColumns
tableSectionBuilder1.NumberOfRows = nRows
tableSectionBuilder1.Style.TableSectionStyle.RowHeight = 10.0
tableSectionBuilder1.ColumnWidth = 50
tableSectionBuilder1.Origin.Origin.SetValue(Nothing, Nothing, OriginP)
Dim nXObject1 As NXOpen.NXObject = Nothing
nXObject1 = tableSectionBuilder1.Commit()
Try
Dim tables() As NXOpen.NXObject
tables = tableSectionBuilder1.GetCommittedObjects()
lw.WriteLine(tables.Length.ToString)
table_finally = CType(tables(0), NXOpen.Annotations.TableSection)
tableSectionBuilder1.Destroy()
Catch ex As Exception
lw.WriteLine(ex.Message)
End Try
Dim tabnote As NXOpen.Tag = table_finally.Tag
Return tabnote
End Function
re: table section tag
nXObject1 will be the created table section.
Try this:
Public Function NXCreateTable(ByVal nRows As Integer, ByVal nColumns As Integer, ByVal OriginP As Point3d) As NXOpen.Tag
Dim nullNXOpen_Annotations_TableSection As NXOpen.Annotations.TableSection = Nothing
Dim tableSectionBuilder1 As NXOpen.Annotations.TableSectionBuilder = Nothing
tableSectionBuilder1 = theSession.Parts.Work.Annotations.TableSections.CreateTableSectionBuilder(nullNXOpen_Annotations_TableSection)
tableSectionBuilder1.RowHeight = 10.0
tableSectionBuilder1.NumberOfColumns = nColumns
tableSectionBuilder1.NumberOfRows = nRows
tableSectionBuilder1.Style.TableSectionStyle.RowHeight = 10.0
tableSectionBuilder1.ColumnWidth = 50
tableSectionBuilder1.Origin.Origin.SetValue(Nothing, Nothing, OriginP)
Dim nXObject1 As NXOpen.NXObject = Nothing
Try
nXObject1 = tableSectionBuilder1.Commit()
Catch ex As Exception
lw.WriteLine(ex.Message)
Finally
tableSectionBuilder1.Destroy()
End Try
lw.WriteLine("committed object type: " & nXObject1.GetType.ToString)
lw.WriteLine("committed object tag: " & nXObject1.Tag.ToString)
Return nXObject1.Tag
End Function
NXOpen vs UF
Yeah I tried that and I tried having a function to select the table with the correct type/subtype of tabular note. Still the UF.Tabnot.Method refused to use the tag. So instead I looked at another solution and fixed the issue! Implementing these two lines of code cut down the table building process from 14 minutes to 3 minutes. Row generation takes about a minute and filling the cells takes the rest of the time. Since I'm testing this on one of our most complex parts, I don't think we'll need to refine the time more than that.
ufs.Disp.SetDisplay(UFConstants.UF_DISP_SUPPRESS_DISPLAY)
'CODE HERE FOR BUILDING TABLE
ufs.Disp.SetDisplay(UFConstants.UF_DISP_UNSUPPRESS_DISPLAY)
ufs.Tabnot.Update(tabnote)
re: table section vs tabular note
Glad to hear you greatly improved the performance of your code.
I've learned that tabular notes can be made of several table sections and the API isn't always clear which one is needed for a particular function. If the table section tag (returned in my previous code) caused issues in your code, perhaps the functions were expecting the table tag instead. You can get the tabular note given a section with the AskTabularNoteOfSection function.