傾斜角度を設定する(.NET)

傾斜角度は、文字を前方または後方に傾ける角度を指定します。この角度は、垂直軸(90 度)からのオフセットを表します。傾斜角度を設定するには、ObliquingAngle プロパティを使用して文字スタイルを変更するか、テキスト オブジェクトの Oblique プロパティを使用します。傾斜角度はラジアン単位で指定します。正の角度は右への傾きを示します。負の値は 2π を加えて等価な正の角度に変換します。

斜体文字を作成する

次の例は、1 行文字オブジェクトを作成し、次にオブジェクトを 45 度傾斜させます。

C# の例

using Autodesk.AutoCAD.Runtime;
using Autodesk.AutoCAD.ApplicationServices;
using Autodesk.AutoCAD.DatabaseServices;
using Autodesk.AutoCAD.Geometry;
 
[CommandMethod("ObliqueText")]
public static void ObliqueText()
{
    // 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 single-line text object
        using (DBText acText = new DBText())
        {
            acText.Position = new Point3d(3, 3, 0);
            acText.Height = 0.5;
            acText.TextString = "Hello, World.";

            // Change the oblique angle of the text object to 45 degrees(0.707 in radians)
            acText.Oblique = 0.707;

            acBlkTblRec.AppendEntity(acText);
            acTrans.AddNewlyCreatedDBObject(acText, true);
        }

        // Save the changes and dispose of the transaction
        acTrans.Commit();
    }
}