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: 

Drawing View Label Text Size

4 REPLIES 4
SOLVED
Reply
Message 1 of 5
stuartmp
2018 Views, 4 Replies

Drawing View Label Text Size

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

 

 

4 REPLIES 4
Message 2 of 5
stuartmp
in reply to: stuartmp

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

Message 3 of 5
ADNpati
in reply to: stuartmp

 

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>"

 
It changes text font size to 25 and colour to red

 

Note that the font size is specified in 
centimeters
Mechanical Engineer
Inventor Applications Engineer

--------------------------------------------------------------------------------------

If my solution seems to remedy your problem, please press the Accept Solution button, Some KUDOS -

-------------------------------------------------------------------------------------
Message 4 of 5
stuartmp
in reply to: stuartmp

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.

 

 

 

 

 

Message 5 of 5
foxrid3r
in reply to: stuartmp

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:

 

Multiline Title

 

 

 

 

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.

Post to forums  

Autodesk Design & Make Report