CAD开发者社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

ObjectARX 开发指南

分配字体 (.NET)

2023-1-1 12:20| 发布者: admin| 查看: 324| 评论: 0|来自: AutoCAD

字体定义构成每个字符集的文本字符的形状。一种字体可以由多种样式使用。使用该属性设置文本样式的字体文件。可以将 TrueType 或 AutoCAD 编译的 SHX 字体指定给文本样式。FileName

设置文本字体

下面的示例使用活动文本样式的属性获取当前字体值,然后将字体的字样更改为“PlayBill”。若要查看更改字体的效果,请在运行示例之前向当前绘图添加一些多行或单行文本。请注意,如果您的系统上没有 PlayBill 字体,则需要替换您拥有的字体才能使此示例正常工作。Font

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
 
<CommandMethod("UpdateTextFont")> _
Public Sub UpdateTextFont()
    '' Get the current document and database
    Dim acDoc As Document = Application.DocumentManager.MdiActiveDocument
    Dim acCurDb As Database = acDoc.Database
 
    '' Start a transaction
    Using acTrans As Transaction = acCurDb.TransactionManager.StartTransaction()
 
        '' Open the current text style for write
        Dim acTextStyleTblRec As TextStyleTableRecord
        acTextStyleTblRec = acTrans.GetObject(acCurDb.Textstyle, _
                                              OpenMode.ForWrite)
 
        '' Get the current font settings
        Dim acFont As Autodesk.AutoCAD.GraphicsInterface.FontDescriptor
        acFont = acTextStyleTblRec.Font
 
        '' Update the text style's typeface with "PlayBill"
        Dim acNewFont As Autodesk.AutoCAD.GraphicsInterface.FontDescriptor
        acNewFont = New  _
          Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("PlayBill", _
                                                            acFont.Bold, _
                                                            acFont.Italic, _
                                                            acFont.CharacterSet, _
                                                            acFont.PitchAndFamily)
 
        acTextStyleTblRec.Font = acNewFont
 
        acDoc.Editor.Regen()
 
        '' Save the changes and dispose of the transaction
        acTrans.Commit()
    End Using
End Sub

C#

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
 
[CommandMethod("UpdateTextFont")]
public static void UpdateTextFont()
{
    // Get the current document and database
    Document acDoc = Application.DocumentManager.MdiActiveDocument;
    Database acCurDb = acDoc.Database;
 
    // Start a transaction
    using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
    {
        // Open the current text style for write
        TextStyleTableRecord acTextStyleTblRec;
        acTextStyleTblRec = acTrans.GetObject(acCurDb.Textstyle,
                                              OpenMode.ForWrite) as TextStyleTableRecord;
 
        // Get the current font settings
        Autodesk.AutoCAD.GraphicsInterface.FontDescriptor acFont;
        acFont = acTextStyleTblRec.Font;
 
        // Update the text style's typeface with "PlayBill"
        Autodesk.AutoCAD.GraphicsInterface.FontDescriptor acNewFont;
        acNewFont = new
          Autodesk.AutoCAD.GraphicsInterface.FontDescriptor("PlayBill",
                                                            acFont.Bold,
                                                            acFont.Italic,
                                                            acFont.CharacterSet,
                                                            acFont.PitchAndFamily);
 
        acTextStyleTblRec.Font = acNewFont;
 
        acDoc.Editor.Regen();
 
        // Save the changes and dispose of the transaction
        acTrans.Commit();
    }
}

VBA/ActiveX 代码参考

Sub 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
End Sub

路过

雷人

握手

鲜花

鸡蛋

最新评论

QQ|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 )

GMT+8, 2024-5-19 13:55

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

返回顶部