新しく作成されたマルチ テキストは、現在の文字スタイルの特性を受け継ぎます。既定の文字スタイルは STANDARD です。書式を個々の文字に適用したり、プロパティをマルチ テキスト オブジェクトに適用すれば、既定の文字スタイルを変更できます。書式または特殊文字は、このセクションに示されたメソッドを使用すると表示できます。
文字スタイル、位置合わせ、幅、回転といった方向オプションは、マルチ テキストの境界に含まれるすべての文字に影響を与え、特定の単語または文字には影響しません。マルチ テキスト オブジェクトの位置合わせを変更するには Attachment プロパティを使用し、回転角度をコントロールするには Rotation プロパティを使用します。
TextStyleId プロパティは、マルチ テキスト オブジェクトのフォントおよび書式特性を設定します。マルチ テキストを作成するとき、既存の文字スタイルのリストの中から、使用したい文字スタイルを選択できます。文字の任意の部分に適用される書式特性を含むマルチ テキスト オブジェクトのスタイルを変更すると、そのスタイルはオブジェクト全体に適用され、文字書式の中には保持されないものもあります。たとえば、TrueType スタイルから SHX フォントへの変更や、他の TrueType フォントへの変更により、オブジェクト全体に対してマルチ テキストが新規フォントを使うようになります。そして文字書式はすべて失われます。
アンダーライン、文字またはフォントの積み重ねといった書式オプションは、個々の単語または段落内の個々の文字に適用できます。色、フォント、文字の高さを変更できます。テキスト文字列の間隔を変更したり、文字列自体の幅を広くできます。
中括弧({ })を使用すると、括弧内の文字だけに書式変更を適用できます。括弧は、8 レベルまでネストできます。
制御コードとして ASCII コードを行または段落内に入れて、書式、あるいは許容差記号もしくは寸法記号といった特殊文字を指示できます。
図中の文字を作成するには、次の制御文字を使用することができます(この文字列に対応する ASCII コードは、図の後の例を参照してください)。
{{¥H1.5x; Big text} ¥A2; over text¥A1;/¥A0; under text}
次の例では、マルチ テキスト オブジェクトを作成して書式を設定します。
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();
}
}
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
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
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