引出線の関連付け(.NET)

引出線は、注釈に関連付けられています。そのため、注釈を移動すると、引出線の終点もそれに応じて移動します。文字および公差記入枠の注釈を移動すると、最後の引出線セグメントは、注釈と最後から 2 番目の引出線の点との関係に応じて、注釈の右側または左側に変更されます。注釈の中点が引出線の最後から 2 番目の点の右側にある場合は、引出線は右側に付きます。そうでない場合は、左側に付きます。

EraseAdd (ブロックを追加)、または WBlock メソッドのいずれかを使用して図面からオブジェクトを削除すると、関連付けが失われます。引出線とその注釈を 1 回の操作でまとめて複写した場合は、関連付けが保持されます。個別にコピーした場合、それらは自動調整されません。引出線オブジェクトのみを複写したり、注釈を削除するなどして、両者の関連付けが失われた場合は、その理由に関わらず、フック ラインが引出線から除去されます。

引出線を注釈に関連付ける

次の例は、MText オブジェクトを作成します。次に、この MText オブジェクトを注釈にして引出線を記入します。

VB.NET

Imports Autodesk.AutoCAD.Runtime
Imports Autodesk.AutoCAD.ApplicationServices
Imports Autodesk.AutoCAD.DatabaseServices
Imports Autodesk.AutoCAD.Geometry
 
<CommandMethod("AddLeaderAnnotation")> _
Public Sub AddLeaderAnnotation()
    '' Get the current 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 the MText annotation
        Using acMText As MText = New MText()
            acMText.Contents = "Hello, World."
            acMText.Location = New Point3d(5, 5, 0)
            acMText.Width = 2

            '' Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acMText)
            acTrans.AddNewlyCreatedDBObject(acMText, True)

            '' Create the leader with annotation
            Using acLdr As Leader = New Leader()
                acLdr.AppendVertex(New Point3d(0, 0, 0))
                acLdr.AppendVertex(New Point3d(4, 4, 0))
                acLdr.AppendVertex(New Point3d(4, 5, 0))
                acLdr.HasArrowHead = True

                '' Add the new object to Model space and the transaction
                acBlkTblRec.AppendEntity(acLdr)
                acTrans.AddNewlyCreatedDBObject(acLdr, True)

                '' Attach the annotation after the leader object is added
                acLdr.Annotation = acMText.ObjectId
                acLdr.EvaluateLeader()
            End Using
        End Using

        '' Commit 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("AddLeaderAnnotation")]
public static void AddLeaderAnnotation()
{
    // Get the current 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 the MText annotation
        using (MText acMText = new MText())
        {
            acMText.Contents = "Hello, World.";
            acMText.Location = new Point3d(5, 5, 0);
            acMText.Width = 2;

            // Add the new object to Model space and the transaction
            acBlkTblRec.AppendEntity(acMText);
            acTrans.AddNewlyCreatedDBObject(acMText, true);

            // Create the leader with annotation
            using (Leader acLdr = new Leader())
            {
                acLdr.AppendVertex(new Point3d(0, 0, 0));
                acLdr.AppendVertex(new Point3d(4, 4, 0));
                acLdr.AppendVertex(new Point3d(4, 5, 0));
                acLdr.HasArrowHead = true;

                // Add the new object to Model space and the transaction
                acBlkTblRec.AppendEntity(acLdr);
                acTrans.AddNewlyCreatedDBObject(acLdr, true);

                // Attach the annotation after the leader object is added
                acLdr.Annotation = acMText.ObjectId;
                acLdr.EvaluateLeader();
            }
        }

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

VBA/ActiveX コード リファレンス

Sub AddLeaderAnnotation()
    Dim leaderObj As AcadLeader
    Dim mtextObj As AcadMText
    Dim points(0 To 8) As Double
    Dim insertionPoint(0 To 2) As Double
    Dim width As Double
    Dim leaderType As Integer
    Dim annotationObject As Object
    Dim textString As String, msg As String
 
    ' Create the MText object in model space
    textString = "Hello, World."
    insertionPoint(0) = 5
    insertionPoint(1) = 5
    insertionPoint(2) = 0
    width = 2
    Set mtextObj = ThisDrawing.ModelSpace. _
                       AddMText(insertionPoint, width, textString)
 
    ' Data for Leader
    points(0) = 0: points(1) = 0: points(2) = 0
    points(3) = 4: points(4) = 4: points(5) = 0
    points(6) = 4: points(7) = 5: points(8) = 0
    leaderType = acLineWithArrow
 
    ' Create the Leader object in model space and associate
    ' the MText object with the leader
    Set annotationObject = mtextObj
    Set leaderObj = ThisDrawing.ModelSpace. _
                        AddLeader(points, annotationObject, leaderType)
 
    ZoomAll
End Sub