新创建的多行文本会自动采用当前文本样式的特征。默认文本样式为 STANDARD。可以通过将格式应用于单个字符并将属性应用于多行文本对象来覆盖默认文本样式。您还可以使用本节中介绍的方法指示格式或特殊字符。 样式、对齐、宽度和旋转等方向选项会影响多行文本边界内的所有文本,而不是特定的单词或字符。使用该属性更改多行文本对象的对齐方式,并使用该属性控制旋转角度。AttachmentRotation 该属性设置多行文本对象的字体和格式特征。创建多行文本时,可以从现有样式列表中选择要使用的样式。当您更改将字符格式应用于文本的任何部分的多行文本对象的样式时,该样式将应用于整个对象,并且可能不会保留某些字符格式。例如,从 TrueType 样式更改为使用 SHX 字体的样式或另一种 TrueType 字体会导致多行文本对整个对象使用新字体,并且任何字符格式都将丢失。TextStyleId 格式选项(如下划线、堆叠文本或字体)可以应用于段落中的单个单词或字符。您还可以更改颜色、字体和文本高度。您可以更改文本字符之间的空格或增加字符的宽度。 使用大括号 ({ }) 仅对大括号内的文本应用格式更改。您可以嵌套大括号,深度可达八层。 您还可以在行或段落中输入控制代码的 ASCII 等效项,以指示格式或特殊字符,例如公差或尺寸标注符号。 以下控制字符可用于创建图中的文本。(有关此字符串的 ASCII 等效项,请参阅图中的示例。 {{\H1.5x;大文本} \A2;在文本上\A1;/\A0;在文本下} 使用控制字符设置文本格式下面的示例创建一个多行文本对象并设置其格式。 VB.NETImports Autodesk.AutoCAD.Runtime Imports Autodesk.AutoCAD.ApplicationServices Imports Autodesk.AutoCAD.DatabaseServices Imports Autodesk.AutoCAD.Geometry <CommandMethod("FormatMText")> _ Public Sub FormatMText() '' 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 Block table for read Dim acBlkTbl As BlockTable acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, _ OpenMode.ForRead) '' Open the Block table record Model space for write Dim acBlkTblRec As BlockTableRecord acBlkTblRec = acTrans.GetObject(acBlkTbl(BlockTableRecord.ModelSpace), _ OpenMode.ForWrite) '' Create a multiline text object Using acMText As MText = New MText() acMText.Location = New Point3d(2, 2, 0) acMText.Width = 4.5 acMText.Contents = "{{\H1.5x; Big text}\A2; over text\A1;/\A0;under text}" acBlkTblRec.AppendEntity(acMText) acTrans.AddNewlyCreatedDBObject(acMText, True) End Using '' 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; using Autodesk.AutoCAD.Geometry; [CommandMethod("FormatMText")] public static void FormatMText() { // 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 Block table for read BlockTable acBlkTbl; acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId, OpenMode.ForRead) as BlockTable; // Open the Block table record Model space for write BlockTableRecord acBlkTblRec; acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord; // Create a multiline text object using (MText acMText = new MText()) { acMText.Location = new Point3d(2, 2, 0); acMText.Width = 4.5; acMText.Contents = "{{\\H1.5x; Big text}\\A2; over text\\A1;/\\A0;under text}"; acBlkTblRec.AppendEntity(acMText); acTrans.AddNewlyCreatedDBObject(acMText, true); } // Save the changes and dispose of the transaction acTrans.Commit(); } } VBA/ActiveX 代码参考Sub FormatMText() Dim mtextObj As AcadMText Dim insertPoint(0 To 2) As Double Dim width As Double Dim textString As String insertPoint(0) = 2 insertPoint(1) = 2 insertPoint(2) = 0 width = 4.5 ' Define the ASCII characters for the control characters Dim OB As Long ' Open Bracket { Dim CB As Long ' Close Bracket } Dim BS As Long ' Back Slash \ Dim FS As Long ' Forward Slash / Dim SC As Long ' Semicolon ; OB = Asc("{") CB = Asc("}") BS = Asc("\") FS = Asc("/") SC = Asc(";") ' Assign the text string the following line of control ' characters and text characters: ' {{\H1.5x; Big text}\A2; over text\A1;/\A0;under text} textString = Chr(OB) + Chr(OB) + Chr(BS) + "H1.5x" _ + Chr(SC) + "Big text" + Chr(CB) + Chr(BS) + "A2" _ + Chr(SC) + "over text" + Chr(BS) + "A1" + Chr(SC) _ + Chr(FS) + Chr(BS) + "A0" + Chr(SC) + "under text" _ + Chr(CB) ' Create a text Object in model space Set mtextObj = ThisDrawing.ModelSpace. _ AddMText(insertPoint, width, textString) ZoomAll End Sub 相关概念父主题: |
|Archiver|CAD开发者社区 ( 苏ICP备2022047690号-1 苏公网安备32011402011833)
GMT+8, 2025-1-8 19:13
Powered by Discuz! X3.4
Copyright © 2001-2021, Tencent Cloud.