Having trouble Changing text font size in a drawing sketch
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
I am having trouble changing the font size within a sketch that is used as part of a border title.
I have tried a number of different ways to do this all of which usually fail with an error relating the the code that is trying to change the font size.
It should be noted that the code works as it should without the extra code that is trying to change the font size.
Below are some snippets of the code that was used to change the font size.
----------------------------------------------------------------------------------------------------
Public Sub Main SketchTextAdd()
' a reference to the drawing document.
' This assumes a drawing document is active.
Dim oDrawDoc As DrawingDocument
oDrawDoc = ThisApplication.ActiveDocument
' Create a new sketch on the active sheet.
Dim oSketch As Inventor.Sketch
oSketch = oDrawDoc.ActiveSheet.Sketches.Add
' Open the sketch for edit so the text boxes can be created.
' This is only required for drawing sketches, not part.
oSketch.Edit
'Identify border type
Dim oBorder = ActiveSheet.Border
Dim oTG As TransientGeometry
oTG = ThisApplication.TransientGeometry
' Create text with simple string as input. Since this doesn't use
' any text overrides, it will default to the active text style.
Dim sText As String
sText = InputBox("Enter new Title Text", "Secondary Title ", "")
iProperties.Value("Custom", "Second Title "& ActiveSheet.Name) = sText
Dim oTextBox As Inventor.TextBox
Dim oStyle As TextStyle
For Each oTextBox In oTextBoxes
oStyle = oTextBox.Style
oStyle.Font = "Arial"
oStyle.FontSize = 1
Next
If oBorder = "A3" Then
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(22.7, 3.2),oTG.CreatePoint2d(35,2.4), sText)
Else If oBorder = "A4" Then
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(10.39, 3.2),oTG.CreatePoint2d(22,2.4), sText)
Else If oBorder = "A4_P" Then
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(11.15, 6.195), oTG.CreatePoint2d(20.25, 4), sText)
End If
oSketch.ExitEdit
End Sub
---------------------------------------------------------------------------------------------------
and I have also tried the following snippet of code to try and change the font size.
---------------------------------------------------------------------------------------------------
Dim oTextBox As Inventor.TextBox
If oBorder = "A3" Then
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(22.7, 3.2),oTG.CreatePoint2d(35,2.4), sText)
Else If oBorder = "A4" Then
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(10.39, 3.2),oTG.CreatePoint2d(22,2.4), sText)
Else If oBorder = "A4_P" Then
oTextBox.FormattedText = "<StyleOverride Fontsize = '0.5'>" & sText & "</StyleOverride>"
oTextBox = oSketch.TextBoxes.AddByRectangle(oTG.CreatePoint2d(11.15, 6.195), oTG.CreatePoint2d(20.25, 4), sText)
End If
oSketch.ExitEdit
End Sub
----------------------------------------------------------------------------------------------------
I hope someone can help.