Community
Inventor Programming - iLogic, Macros, AddIns & Apprentice
Inventor iLogic, Macros, AddIns & Apprentice Forum. Share your knowledge, ask questions, and explore popular Inventor topics related to programming, creating add-ins, macros, working with the API or creating iLogic tools.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Custom Table FontSize

2 REPLIES 2
Reply
Message 1 of 3
Anonymous
484 Views, 2 Replies

Custom Table FontSize

Hi

I used the create custom table from the SDK examples and added the following instruction to the Formatting overide.

Does anybody know what I am doing wrong?

oFormat.TextStyle.FontSize = 2


'-------FULL SCRIPT------

Public Sub CreateCustomTable()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Set the column titles
Dim oTitles(1 To 3) As String
oTitles(1) = "Part Number"
oTitles(2) = "Quantity"
oTitles(3) = "Material"

' Set the contents of the custom table (contents are set row-wise)
Dim oContents(1 To 9) As String
oContents(1) = "1"
oContents(2) = "1"
oContents(3) = "Brass"
oContents(4) = "2"
oContents(5) = "2"
oContents(6) = "Aluminium"
oContents(7) = "3"
oContents(8) = "1"
oContents(9) = "Steel"

' Set the column widths (defaults to the column title width if not specified)
Dim oColumnWidths(1 To 3) As Double
oColumnWidths(1) = 2.5
oColumnWidths(2) = 2.5
oColumnWidths(3) = 4

Dim oRowHeights(1 To 3) As Double
oRowHeights(1) = 0.25
oRowHeights(2) = 0.25
oRowHeights(3) = 0.25


' Create the custom table
Dim oCustomTable As CustomTable


Set oCustomTable = oSheet.CustomTables.Add("My Table", ThisApplication.TransientGeometry.CreatePoint2d(15, 15), _
3, 3, oTitles, oContents, oColumnWidths, oRowHeights)

' Change the 3rd column to be left justified.
oCustomTable.Columns.Item(3).ValueHorizontalJustification = kAlignTextLeft

' Create a table format object
Dim oFormat As TableFormat
Set oFormat = oSheet.CustomTables.CreateTableFormat


' Set outside line weight.
oFormat.OutsideLineWeight = 0.05

'---PROBLEM---
oFormat.TextStyle.FontSize = 2


' Modify the table formats
oCustomTable.OverrideFormat = oFormat

End Sub
2 REPLIES 2
Message 2 of 3
Anonymous
in reply to: Anonymous

Here's a modified version of the code that works.

The issue in your code is that when you create a new TableFormat object most
if it is unitialized, indicating those properties have not been set.
Because of this the TextStyle property of the TableFormat object will not
return a TextStyle. That's why it's failing. Instead, you need to use an
existing text style, or create a new one and use it to assign to the
TableFormat object. The code below does this.

Public Sub CreateCustomTable()
' Set a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
Set oDrawDoc = ThisApplication.ActiveDocument

' Set a reference to the active sheet.
Dim oSheet As Sheet
Set oSheet = oDrawDoc.ActiveSheet

' Set the column titles
Dim oTitles(1 To 3) As String
oTitles(1) = "Part Number"
oTitles(2) = "Quantity"
oTitles(3) = "Material"

' Set the contents of the custom table (contents are set row-wise)
Dim oContents(1 To 9) As String
oContents(1) = "1"
oContents(2) = "1"
oContents(3) = "Brass"
oContents(4) = "2"
oContents(5) = "2"
oContents(6) = "Aluminium"
oContents(7) = "3"
oContents(8) = "1"
oContents(9) = "Steel"

' Set the column widths (defaults to the column title width if not
specified)
Dim oColumnWidths(1 To 3) As Double
oColumnWidths(1) = 2.5
oColumnWidths(2) = 2.5
oColumnWidths(3) = 4

Dim oRowHeights(1 To 3) As Double
oRowHeights(1) = 0.25
oRowHeights(2) = 0.25
oRowHeights(3) = 0.25

' Create the custom table
Dim oCustomTable As CustomTable

Set oCustomTable = oSheet.CustomTables.Add("My Table",
ThisApplication.TransientGeometry.CreatePoint2d(15, 15), _
3, 3, oTitles, oContents,
oColumnWidths, oRowHeights)

' Change the 3rd column to be left justified.
oCustomTable.Columns.Item(3).ValueHorizontalJustification =
kAlignTextLeft

' Create a new text style by copying the current one used for the text
box.
Dim oTextStyle As TextStyle
Set oTextStyle = oCustomTable.DataTextStyle.Copy("sCopy of " &
oCustomTable.DataTextStyle.Name)

' Set the font size for the new style
oTextStyle.FontSize = 2

' Create a table format object
Dim oFormat As TableFormat
Set oFormat = oSheet.CustomTables.CreateTableFormat

' Set some of the properties of the table format.
oFormat.OutsideLineWeight = 0.05
oFormat.TextStyle = oTextStyle

' Modify the table formats
oCustomTable.OverrideFormat = oFormat
End Sub

--
Brian Ekins
Autodesk Inventor API
Message 3 of 3
Anonymous
in reply to: Anonymous

Hi Brain

Sorry for delay in getting back to you, as I have been side tracked for a week.

Many thanks for you explanation and code snippet. It works a treat.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Technology Administrators


Autodesk Design & Make Report