Inventor Customization

Reply
Active Contributor
stuartmp
Posts: 29
Registered: ‎01-16-2008
Message 1 of 4 (479 Views)
Accepted Solution

Drawing View Label Text Size

479 Views, 3 Replies
01-28-2013 06:53 PM

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

 

 

Active Contributor
stuartmp
Posts: 29
Registered: ‎01-16-2008
Message 2 of 4 (467 Views)

Re: Drawing View Label Text Size

01-28-2013 07:55 PM 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

Distinguished Contributor
ADNpati
Posts: 125
Registered: ‎07-01-2012
Message 3 of 4 (465 Views)

Re: Drawing View Label Text Size

01-28-2013 08:01 PM 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 -

-------------------------------------------------------------------------------------
Active Contributor
stuartmp
Posts: 29
Registered: ‎01-16-2008
Message 4 of 4 (452 Views)

Re: Drawing View Label Text Size

01-29-2013 03:28 PM 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.

 

 

 

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community


Inventor Exchange Apps

Created by the community for the community, Autodesk Exchange Apps for Autodesk Inventor helps you achieve greater speed, accuracy, and automation from concept to manufacturing.

Connect with Inventor

Twitter

Facebook

Blogs

Pinterest

Youtube