I've been working through the VBA code in this post
attempting to convert it into iLogic (though this probably is an unnecessary complication), but I can't seem to figure out how to bypass all the table formatting and just place a table based on an already defined table style in my style manager.
Do I have to declare the column header, width, rows and data when I use this?
oSheet.CustomTables.Add(...long list of things which I already have in the Style Manager...)
Or can I declare the active table style, then place a new table?
Dim oActiveTableStyle As TableStyle
oActiveTableStyle = oDrawingDocument.StylesManager.TableStyles("Predefined Style Name Goes Here")
BrandonBG
Inventor 2015
Hi Brandon,
The Add method for a custom table has required parameters and some that are optional. This is from the API help. The parameters with square brackets are optional. Farther below is my iLogic code I used to test. It only uses the required parameters. (same as the VBA code you mentioned)
Syntax
CustomTables.Add( Title As String, PlacementPoint As Point2d, NumberOfColumns As Long, NumberOfRows As Long, ColumnTitles() As String, [Contents] As Variant, [ColumnWidths] As Variant, [RowHeights] As Variant, [MoreInfo] As Variant ) As CustomTable
I don't see a way to add a table using the API without having to provide those required parameters. Also in my tests if the current table style has settings for the columns they can effect the results of the Add method.
Here is the iLogic rule:
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisDoc.Document
' Set a reference to the active sheet.
Dim oSheet As Sheet
oSheet = oDrawDoc.ActiveSheet
If oSheet.CustomTables.count > 0 Then
oSheet.CustomTables.Item(1).Delete()
End If
'Set the column titles & Create the custom table
Dim oInspTblTitle As String
oInspTblTitle = "INSPECTION DIMENSIONS"
Dim oTitles(2) As String
oTitles(0) = "DIMENSION NUMBER"
oTitles(1) = "DESIGN"
oTitles(2) = "ACTUAL"
'oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.HeadingGap = 0.125
'oDrawDoc.StylesManager.ActiveStandardStyle.ActiveObjectDefaults.TableStyle.ColumnValueHorizontalJustification = HorizontalTextAlignmentEnum.kAlignTextCenter
Dim oGenDimCount As Integer = 0
Dim oDim As DrawingDimension
For Each oDim In oSheet.DrawingDimensions
If oDim.IsInspectionDimension Then
oGenDimCount = oGenDimCount + 1
End If
Next
Dim oInspDimTable As CustomTable
'oInspDimTable = oSheet.CustomTables.Add(oInspTblTitle, ThisApplication.TransientGeometry.CreatePoint2d(1.5, 27), 3, oGenDimCount, oTitles)
Dim pnt As Point2d = ThisApplication.TransientGeometry.CreatePoint2d(1.5, 27)
oInspDimTable = oSheet.CustomTables.Add(oInspTblTitle, pnt, 3, oGenDimCount, oTitles)
'oInspDimTable = oSheet.CustomTables.Add(oInspTblTitle, pnt, , , oTitles)
'Get Inspection Dimension Data
Dim oInspDim As DrawingDimension 'WB commented
Dim oInspDimShape As InspectionDimensionShapeEnum
Dim oInspDimText As DimensionText
Dim oInspDimText2 As Object
Dim oInspDimNumber As String '= ""
Dim oInspDimRate As String' = ""
Dim i As Integer
Dim oCellInspDimNum As Cell
Dim oCellInspDim As Cell
i = 1
For Each oSheet In oDrawDoc.Sheets
For Each oInspDim In oSheet.DrawingDimensions
If oInspDim.IsInspectionDimension Then
oInspDim.GetInspectionDimensionData(oInspDimShape, oInspDimNumber, oInspDimRate)
oInspDimText = oInspDim.Text
oInspDimText2 = ThisApplication.UnitsOfMeasure.GetPreciseStringFromValue(oInspDim.ModelValue, UnitsTypeEnum.kInchLengthUnits)
oCellInspDimNum = oInspDimTable.Rows.Item(i).Item("DIMENSION NUMBER")
oCellInspDimNum.Value = oInspDimNumber
oCellInspDim = oInspDimTable.Rows.Item(i).Item("DESIGN")
oCellInspDim.Value = oInspDimText2
i = i + 1
End If
Next
Next
oInspDimTable.Sort("DIMENSION NUMBER", True)
Dim oRow As Row
For Each oRow In oInspDimTable.Rows
If oCellInspDimNum.Value <> oInspDimNumber Then
oRow.Delete()
End If
Next
Thanks,
Wayne
Thanks Wayne. Here's the ugly code I came up with to workaround the issue of not being able to call a table style before generating it. I activate a table style (do I need to?), generate the table, and then kind of backtrack and apply the active table style to the table. It appears to work for the purpose I need, although I have a feeling I'm overcomplicating the code. And I haven't used any error checking.
Brandon BG
Inventor 2015
Dim oDrawingDocument As DrawingDocument oDrawingDocument = ThisApplication.ActiveDocument Dim oSheet As Sheet oSheet = oDrawingDocument.ActiveSheet Dim oCustomTable As CustomTable Dim oCustomTables As CustomTables oCustomTables = oSheet.CustomTables For Each oCustomTable In oCustomTables If oCustomTable.Title = "FIELD VERIFICATION DIMENSIONS" Then oCustomTable.Delete() End If Next Dim oInspectionDimension As DrawingDimension Dim oInspectionDimensionShape As InspectionDimensionShapeEnum Dim oInspectionDimensionText As DimensionText Dim oInspectionDimensionString As String Dim oCellInspectionDimensionItem As Cell Dim oCellInspectionDimension As Cell Dim oInspectionDimensionCount As Integer oInspectionDimensionCount = 0 For Each oInspectionDimension In oSheet.DrawingDimensions If oInspectionDimension.IsInspectionDimension Then oInspectionDimensionCount = oInspectionDimensionCount + 1 End If Next Dim oColumnTitle(0 To 3) As String oColumnTitle(0) = "Column1" oColumnTitle(1) = "Column2" oColumnTitle(2) = "Column3" oColumnTitle(3) = "Column4" Dim oActiveTableStyle As TableStyle Dim oTableTitle As String oActiveTableStyle = oDrawingDocument.StylesManager.TableStyles("Field Verification Dimensions") oTableTitle = oActiveTableStyle.Title Dim oFieldVerificationTable As CustomTable oFieldVerificationTable = oSheet.CustomTables.Add(oTableTitle, ThisApplication.TransientGeometry.CreatePoint2d(.635, oSheet.Height-.635), 4, oInspectionDimensionCount, oColumnTitle) Dim oInspectionDimensionCount2 As Integer oInspectionDimensionCount2 = 0 Dim oCellInspectionDimensionRow As Row For Each oInspectionDimension In oSheet.DrawingDimensions If oInspectionDimension.IsInspectionDimension Then oInspectionDimensionCount2 = oInspectionDimensionCount2 + 1 oInspectionDimensionText = oInspectionDimension.Text oInspectionDimensionString = oInspectionDimensionText.Text oCellInspectionDimensionItem = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Column1") oCellInspectionDimensionItem.Value = oInspectionDimensionCount2 oCellInspectionDimension = oFieldVerificationTable.Rows.Item(oInspectionDimensionCount2).Item("Column2") oCellInspectionDimension.Value = oInspectionDimensionString + "''" End If Next oFieldVerificationTable.Style = oActiveTableStyle