Set style properties of a custom table

By Wayne Brill

To change the properties of a CustomTable you can create a new style (TableFormat) set its properties as needed and then assign it to the custom table using the OverrideFormat property.

VBA example: (select a table before running)

Sub customTableChangeStyle()
 
    Dim oDrw As DrawingDocument
    Set oDrw = ThisApplication.ActiveDocument
    ‘Error will occur if nothing is selected
    ‘select a custom table
    Dim oCT As CustomTable
    Set oCT = oDrw.SelectSet(1)
   
    ‘ create a new table format
    Dim oTF As TableFormat
    Set oTF = oDrw.ActiveSheet.CustomTables. _
                          CreateTableFormat
   
    Dim oTextStyle As TextStyle
    Set oTextStyle = oDrw.StylesManager. _
                              textStyles(1)
   
    oTextStyle.Font = "Arial Black"
    oTextStyle.Color = ThisApplication. _
     TransientObjects.CreateColor(255, 0, 0)
   
    ‘This is in centimeters, use
    ‘Units of Measure to get into other units
    oTextStyle.FontSize = 0.7
   
   ‘ set the textstyle of the style being used
    oTF.TextStyle = oTextStyle
   
    ‘Set inside line color to blue.
    oTF.InsideLineColor = ThisApplication. _
      TransientObjects.CreateColor(0, 0, 255)
   
    ‘set the format for the custom table
    oCT.OverrideFormat = oTF
   
End Sub

VB.NET (Form App) Select table before running

Public Class Form1             Dim m_inventorApp As Inventor.Application _                                          = Nothing             Private Sub Button1_Click(ByVal sender As  _                                    System.Object, _                      ByVal e As System.EventArgs) _                            Handles Button1.Click                 ' Get an active instance of Inventor            Try                m_inventorApp = System.Runtime. _                       InteropServices.Marshal. _           GetActiveObject("Inventor.Application")                 Catch 'Inventor not started                System.Windows.Forms.MessageBox. _                 Show("Start an Inventor session")                Exit Sub            End Try                 'Call the Sub            customTableChangeStyle()        End Sub        Sub customTableChangeStyle()                 Dim oDrw As DrawingDocument            oDrw = m_inventorApp.ActiveDocument            'Error will occur if nothing is selected            'select a custom table            Dim oCT As CustomTable            oCT = oDrw.SelectSet(1)                 ' create a new table format            Dim oTF As TableFormat            oTF = oDrw.ActiveSheet.CustomTables. _                &#160
;                 CreateTableFormat                 Dim oTextStyle As TextStyle            oTextStyle = oDrw.StylesManager. _                                      textStyles(1)                 oTextStyle.Font = "Arial Black"            oTextStyle.Color = m_inventorApp. _             TransientObjects.CreateColor(255, 0, 0)                 'This is in centimeters, use            'Units of Measure to get into other units            oTextStyle.FontSize = 0.7                 ' set the textstyle of the style being used            oTF.TextStyle = oTextStyle                 'Set inside line color to blue.            oTF.InsideLineColor = m_inventorApp. _              TransientObjects.CreateColor(0, 0, 255)                 'set the format for the custom table            oCT.OverrideFormat = oTF             End Sub         End Class

Comments

Leave a Reply

Discover more from Autodesk Developer Blog

Subscribe now to keep reading and get access to the full archive.

Continue reading