I created an iLogic rule that will work with an 'active' drawing document, and creates a fairly simple Custom Table 'from scratch'. Within this rule, right after I create the oContents variable, that's where I've filled in the contents of the table. This includes all the cells of all the rows, below the title row and the column header row. Right now I've just used a simple 'For' loop to fill them all in with generic data to help you understand how all the cells are being filled in from the single dimension array of Strings. You can replace that simple loop with a much more detailed section of code which sets the value of each cell individually. I have included some examples of both setting all array values at once, and setting each individually. When setting them all at once, you don't specify the array's size, just set its values. But when setting its values individually, you need to specify the size of the array when you create it (otherwise you will have to keep resizing it to avoid errors).
Here's the code:
If ThisApplication.ActiveDocumentType <> DocumentTypeEnum.kDrawingDocumentObject Then
MsgBox("A Drawing Document must be active for this rule (" & iLogicVb.RuleName & ") to work. Exiting.",vbOKOnly+vbCritical, "WRONG DOCUMENT TYPE")
Exit Sub
End If
Dim oDDoc As DrawingDocument = ThisDrawing.Document
Dim oSheet As Inventor.Sheet = oDDoc.ActiveSheet
Dim oTitle As String = "CUSTOM TABLE TITLE"
Dim oTG As TransientGeometry = ThisApplication.TransientGeometry
Dim oPPoint As Point2d = oTG.CreatePoint2d(0, 0)
Dim oCols As Integer = 5
Dim oRows As Integer = 6
'Number of column titles supplied must match number of columns specified
'Dim oColTitles() As String = {" ", "Dimension L1", "Dimension L2", "Material", "Cost" }
'or
Dim oColTitles(oCols - 1) As String
oColTitles(0) = " " '1st column title
oColTitles(1) = "Column 2 Title" '2nd column title
oColTitles(2) = "Column 3 Title" '3rd column title
oColTitles(3) = "Material" '4th column title
oColTitles(4) = "Cost" '5th column title
'Contents must be a 'single dimension' array of String.
'the number of entries supplied in Contents must match the number of cells in the table
Dim oCells As Integer = (oCols * oRows) -1 'minus the 1, because an array starts at zero, instead of 1
Dim oContents(oCells) As String
For oCell As Integer = 0 To oCells
oContents(oCell) = "Cell " & oCell
Next
'Dim oColWidths() As Double = {1.25, 2.5, 2.5, 1.5, 1.25 }
'or
'could run a function here to determine how wide each column needs to be, then set them individually
Dim oColWidths(oCols - 1) As Double
oColWidths(0) = 1.25 '1st column width
oColWidths(1) = 2.5
oColWidths(2) = 2.5
oColWidths(3) = 1.5
oColWidths(4) = 1.25 '5th column width
'Dim oRowHeights() As Double = {.25, .25, .25, .25, .25, .25 }
'or
'could run a function here to determine how tall each row needs to be, then set them individually
Dim oRowHeights(oRows - 1) As Double
For oRow As Integer = 0 To (oRows-1)
oRowHeights(oRow) = .25
Next
Dim oCTable As CustomTable = oSheet.CustomTables.Add(oTitle, oPPoint, oCols, oRows, oColTitles, oContents, oColWidths, oRowHeights)
If this solved your problem, or answered your question, please click ACCEPT SOLUTION.
Or, if this helped you, please click (LIKE or KUDOS) 👍.
If you have time, please... Vote For My IDEAS 💡or you can Explore My CONTRIBUTIONS
Inventor 2021 Help | Inventor Forum | Inventor Customization Forum | Inventor Ideas Forum
Wesley Crihfield

(Not an Autodesk Employee)