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><Br/>" & _
'"<StyleOverride FontSize='1.'>Qty " & PartFileQty & "</StyleOverride>"
Next
End If
End Sub
Solved! Go to Solution.
Solved by stuartmp. Go to Solution.
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
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>"
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.
The method described by ADNpati works with multilined text. I have successfully underlined the first line of a view label and set text height to 0.187" while changing the font size of the second line to 0.13". See code below:
dim sFirstLine as string dim sSecondLine as string sFirstLine = "A Title" sSecondLine = "Some Description" ' The Inventor API expects dimensions and sizes to be passed in "cm" units. ' Inventor will convert to equivelant units based on styles ' Example: FontSize = '0.475' means set the font size to 0.475 cm or 0.187in oDwgViewLabel.FormattedText = "<StyleOverride FontSize = '0.475' Underline = 'True'>" & sFirstLine & "</StyleOverride>" & _ vbNewLine & "<StyleOverride FontSize = '0.3302' Underline = 'False'>" & sSecondLine & "</StyleOverride>"
Can't find what you're looking for? Ask the community or share your knowledge.