Newly created multiline text automatically assumes the characteristics of the current text style. The default text style is STANDARD. You can override the default text style by applying formatting to individual characters and applying properties to the multiline text object. You also can indicate formatting or special characters using the methods described in this section.
新的文字将自动使用当前文字样式的特征。默认文字样式是 STANDARD。用户可以通过格式化个别字符和对多行文本 对象应用特性来替代默认的文字样式,也可以使用本节介绍的方法指定格式或特殊字符。
Orientation options such as style, justification, width, and rotation affect all text within the multiline text boundary, not specific words or characters. Use the Attachment property to change the justification of a multiline text object, and the Rotation property to control the angle of rotation.
类似于样式、对正、宽度和旋转这些方向选项,可以影响多行文字边框内的所有文字,而不是只影响特定的字或字符。使用 Attachment 特性修改多行文字的对正方式,使用 Rotation 特性控制文字边界的旋转角度。
The TextStyleId property sets the font and formatting characteristics for a multiline text object. As you create multiline text, you can select which style you want to use from a list of existing styles. When you change the style of a multiline text object that has character formatting applied to any portion of the text, the style is applied to the entire object, and some formatting of characters might not be retained. For instance, changing from a TrueType style to a style using an SHX font or to another TrueType font causes the multiline text to use the new font for the entire object, and any character formatting is lost.
使用 TextStyleId 属性设置多行文字的字体和格式特征。当创建多行文字,可以从现有的样式列表中选择要使用的样式。用户修改某个部分应用了字符格式的 MText 对象的样式时,样式将应用到整个对象,但字符的某些格式可能无法保留。例如,如果一种 TrueType 样式更改为使用 SHX 字体或使用其他的 TrueType 字体,将导致整个对象的文字使用新字体,而所有的字符格式都会丢失。
Formatting options such as underlining, stacked text, or fonts can be applied to individual words or characters within a paragraph. You also can change color, font, and text height. You can change the spaces between text characters or increase the width of the characters.
格式选项象下划线、堆叠文字或字体可以应用到段落中的个别单词或字符。用户可以修改颜色、字体和文字高度,还可以修改文字的字符间距或是增加字符的宽度。
Use curly braces ({ }) to apply a format change only to the text within the braces. You can nest braces up to eight levels deep.
使用大括号 ({ }) 可以仅对括号内的文字应用格式修改。用户最多可以设置八层深度的括号。
You also can enter the ASCII equivalent for control codes within lines or paragraphs to indicate formatting or special characters, such as tolerance or dimensioning symbols.
用户也可以在行或段落中输入控制代码的 ASCII 等价值来表示格式或特殊字符,例如公差和标注符号。
The following control characters can be used to create the text in the illustration. (For the ASCII equivalent of this string see the example following the illustration.)
以下控制字符可用来创建图解中的文字。(关于此字符串的 ASCII 等价值,请参见以下图解。)
{{\H1.5x; Big text} \A2; over text\A1;/\A0; under text}
{{\H1.5x; Big text} \A2; over text\A1;/\A0; under text}
For more information about formatting multiline text, see “Format Characters Within Multiline Text” in the AutoCAD User's Guide.
有关设置多行文字格式的详细信息,请参见《AutoCAD 用户手册》中的“设置多行文字中字符的格式”。
The following example creates and formats a multiline text object.
本例创建并格式化一个多行文本对象。
Imports 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
Dim acMText As MText = New MText()
acMText.SetDatabaseDefaults()
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()
End Using
End Sub
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
MText acMText = new MText();
acMText.SetDatabaseDefaults();
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();
}
}