Assign Fonts

AutoCAD ActiveX

 
Assign Fonts
 
 
 

Fonts define the shapes of the text characters that make up each character set. A single font can be used by more than one style. To assign a font to a text style, use the FontFile property of the TextStyle object. By entering the font file containing an AutoCAD-compiled SHX font, you assign that font to the text style.

Set text fonts

This example gets the current font values for the active text style and then changes the typeface for the font to “PlayBill.” The new font is then set using the SetFont method. To see the effects of changing the typeface, add some Mtext or Text to your current drawing before running the example. Note that, if you don't have the PlayBill font on your system, you need to substitute a font you do have in order for this example to work.

Sub Ch4_UpdateTextFont()
      
    MsgBox ("Look at the text now...")
      
    Dim typeFace As String
    Dim SavetypeFace As String
    Dim Bold As Boolean
    Dim Italic As Boolean
    Dim charSet As Long
    Dim PitchandFamily As Long
      
    ' Get the current settings to fill in the
    ' default values for the SetFont method
    ThisDrawing.ActiveTextStyle.GetFont typeFace, _
 Bold, Italic, charSet, PitchandFamily
      
    ' Change the typeface for the font
    SavetypeFace = typeFace
    typeFace = "PlayBill"
    ThisDrawing.ActiveTextStyle.SetFont typeFace, _
 Bold, Italic, charSet, PitchandFamily
    ThisDrawing.Regen acActiveViewport
    MsgBox ("Now see how it looks after changing the font...")
      
    'Restore the original typeface
    ThisDrawing.ActiveTextStyle.SetFont SavetypeFace, _
 Bold, Italic, charSet, PitchandFamily
    ThisDrawing.Regen acActiveViewport
End Sub