Leader Associativity
 
 
 

Leaders are associated with their annotation so that when the annotation moves, the endpoint of the leader moves with it. As you move text and feature control frame annotation, the final leader line segment alternates between attaching to the left side and to the right side of the annotation according to the relation of the annotation to the penultimate (second to last) point of the leader. If the midpoint of the annotation is to the right of the penultimate leader point, then the leader attaches to the right; otherwise, it attaches to the left.

Removing either object from the drawing using either the Erase, Add (to add a block), or WBlock method will break associativity. If the leader and its annotation are copied together in a single operation, the new copy is associative. If they are copied separately, they will non-associative. If associativity is broken for any reason, for example, by copying only the Leader object or by erasing the annotation, the hook line will be removed from the leader.

Associate a leader to the annotation

This example creates an MText object. A leader line is then created using the MText object as its annotation.

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
      Dim acMText As MText = New MText()
      acMText.SetDatabaseDefaults()
      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
      Dim acLdr As Leader = New Leader()
      acLdr.SetDatabaseDefaults()
      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()
  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
      MText acMText = new MText();
      acMText.SetDatabaseDefaults();
      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
      Leader acLdr = new Leader();
      acLdr.SetDatabaseDefaults();
      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 Code Reference