Autodesk Inventor Customization
- Start Article
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic to the Top
- Bookmark
- Subscribe
- Printer Friendly Page
Drawing View Label Text Size
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Hi All.
Is it possible to change the text height of a drawing view label through VBA?
I have tried to change it by creating a new text style manually with the text height I require and then through VBA set the view label to use that style.
The View label takes on the new style but does not change the text height.
I have tried to use 'StyleOverride FontSize=' but I have text that is multi lined and using this command converts all my text onto one line.
Is it possible to change the text height of a drawing view label through VBA?
Below is my code so far,
Sub HoleDetailSheetLabels()
' Declare the Application object
Dim oApp As Inventor.Application
' Obtain the Inventor Application object.
' This assumes Inventor is already running.
'Set oApp = GetObject(, "Inventor.Application")
Set oApp = ThisApplication
' Set a reference to the active document.
' This assumes a document is open.
Dim oDoc As Inventor.Document
Set oDoc = oApp.ActiveDocument
If oDoc.DocumentType <> kDrawingDocumentObject Then
MsgBox "You must be in a Drawing file"
Exit Sub
End If
If oDoc.FileSaveCounter = 0 Then
MsgBox "Please save this file first"
Exit Sub
End If
Dim oSheets As Inventor.sheets
Set oSheets = oDoc.sheets
If oDoc.sheets.Count = 0 Then
MsgBox "Please Add a Drawing Sheet first"
Exit Sub
End If
Dim oActiveSheet As Inventor.sheet
Set oActiveSheet = oDoc.ActiveSheet
If InStr(1, "HOLE DETAIL SHEET", UCase(oActiveSheet.Name), vbTextCompare) > 0 Then
MsgBox "Please ensure you have a Hole Detail Sheet Active First"
Exit Sub
End If
Dim ODwgViews As DrawingViews
Dim ODwgView As DrawingView
Dim Dviewlabel As Inventor.DrawingViewLabel
Set ODwgViews = oDoc.ActiveSheet.DrawingViews
' Set a reference to the GeneralNotes object
Dim oTextStyles As TextStylesEnumerator
Set oTextStyles = oDoc.StylesManager.TextStyles
Dim oTextStyle As TextStyle
For Each oTextStyle In oTextStyles
If oTextStyle.Name = "Hole Detail Sheet View Label Text" Then
Exit For
End If
Next
Dim oldtext As String
If Not oTextStyle Is Nothing Then
For Each ODwgView In ODwgViews
Set Dviewlabel = ODwgView.Label
oldtext = Dviewlabel.Text
Dviewlabel.TextStyle = oTextStyle
'Dviewlabel.FormattedText = "<StyleOverride FontSize='2'>" & Dviewlabel.Text & " </StyleOverride>"
'Dviewlabel.FormattedText = "<StyleOverride FontSize='1.'>Part no. </StyleOverride><StyleOverride FontSize='1.'><Property Document='model' PropertySet='Design Tracking Properties' Property='Part Number' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='5'>PART NUMBER</Property></StyleOverride><Br/>" & _
'"<StyleOverride FontSize='1.'><Property Document='model' PropertySet='Design Tracking Properties' Property='Material' FormatID='{32853F0F-3444-11D1-9E93-0060B03C1CA6}' PropertyID='20'>MATERIAL</Property></StyleOverride
'"<StyleOverride FontSize='1.'>Qty " & PartFileQty & "</StyleOverride>"
Next
End If
End Sub
Solved! Go to Solution.
Re: Drawing View Label Text Size
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
There maybe a better way but for now I have done this
If Not oTextStyle Is Nothing Then
For Each ODwgView In ODwgViews
Set Dviewlabel = ODwgView.Label
Dviewlabel.TextStyle = oTextStyle
oldtext = Dviewlabel.FormattedText
newtext = Replace(oldtext, "FontSize='1.'", "FontSize='" & oTextStyle.FontSize & ".'", 1, , vbTextCompare)
Dviewlabel.FormattedText = newtext
Next
End If
Re: Drawing View Label Text Size
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
The Font Size control is not for the entire View label. Rather, it can be applied to individual characters within the View label.i.e.
different characters can have different overrides. So you'll need to use the
FormattedText property to define such overrides.
For example, for a text box
oTextBox.FormattedText = "<StyleOverride FontSize = '25'>" & "Some Text" & "<StyleOverride Color = '255,0,0'>" & _
"</StyleOverride>" & "</StyleOverride>"
centimeters
Inventor Applications Engineer
--------------------------------------------------------------------------------------
If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -
-------------------------------------------------------------------------------------
Re: Drawing View Label Text Size
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content
Yes what you say is true, but does not work for multi lined text.
Becase I tried it and it convets my multi lined text in to a single line as I said above.
So you need to use the VBA Replace function.
Thanks for you input anyways.

