You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The Leader class represents a leader annotation entity in AutoCAD. A leader is a line or spline with an arrowhead that connects annotation text or blocks to specific features in a drawing. Leaders are commonly used for callouts, notes, and dimensional annotations.
Gets/sets the annotation object (text, block, etc.)
DimStyle
ObjectId
Gets/sets the dimension style
DimScale
double
Gets/sets the dimension scale
ColorIndex
short
Gets/sets the color index
NumVertices
int
Gets the number of vertices
Key Methods
Method
Return Type
Description
AppendVertex(Point3d)
void
Adds a vertex to the leader
GetVertexAt(int)
Point3d
Gets the vertex at the specified index
SetVertexAt(int, Point3d)
void
Sets the vertex at the specified index
RemoveLastVertex()
void
Removes the last vertex
EvaluateLeader()
void
Recalculates the leader geometry
AttachAnnotation(ObjectId)
void
Attaches an annotation to the leader
Code Examples
Example 1: Creating a Simple Leader
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Create leaderLeaderleader=newLeader();leader.SetDatabaseDefaults();// Add vertices (from annotation point to feature)leader.AppendVertex(newPoint3d(10,10,0));// Annotation pointleader.AppendVertex(newPoint3d(5,5,0));// Elbow pointleader.AppendVertex(newPoint3d(0,0,0));// Feature point (arrowhead)// Set propertiesleader.HasArrowHead=true;leader.ColorIndex=1;// Red// Add to drawingbtr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);// Evaluate to update geometryleader.EvaluateLeader();tr.Commit();}
Example 2: Creating Leader with Text Annotation
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;// Create text annotationMTextmtext=newMText();mtext.SetDatabaseDefaults();mtext.Location=newPoint3d(10,10,0);mtext.Contents="This is a note";mtext.TextHeight=2.5;ObjectIdmtextId=btr.AppendEntity(mtext);tr.AddNewlyCreatedDBObject(mtext,true);// Create leaderLeaderleader=newLeader();leader.SetDatabaseDefaults();leader.AppendVertex(newPoint3d(10,10,0));leader.AppendVertex(newPoint3d(5,5,0));leader.AppendVertex(newPoint3d(0,0,0));leader.HasArrowHead=true;// Attach annotationleader.Annotation=mtextId;btr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);leader.EvaluateLeader();tr.Commit();}
Example 3: Creating Splined Leader
using(Transactiontr=db.TransactionManager.StartTransaction()){BlockTableRecordbtr=tr.GetObject(db.CurrentSpaceId,OpenMode.ForWrite)asBlockTableRecord;Leaderleader=newLeader();leader.SetDatabaseDefaults();// Add multiple vertices for smooth curveleader.AppendVertex(newPoint3d(15,15,0));leader.AppendVertex(newPoint3d(12,10,0));leader.AppendVertex(newPoint3d(8,8,0));leader.AppendVertex(newPoint3d(5,5,0));leader.AppendVertex(newPoint3d(0,0,0));// Make it splinedleader.IsSplined=true;leader.HasArrowHead=true;leader.ColorIndex=3;// Greenbtr.AppendEntity(leader);tr.AddNewlyCreatedDBObject(leader,true);leader.EvaluateLeader();tr.Commit();}
Example 4: Reading Leader Properties
using(Transactiontr=db.TransactionManager.StartTransaction()){Leaderleader=tr.GetObject(leaderId,OpenMode.ForRead)asLeader;ed.WriteMessage("\n=== Leader Information ===");ed.WriteMessage($"\nHas Arrowhead: {leader.HasArrowHead}");ed.WriteMessage($"\nHas Hook Line: {leader.HasHookLine}");ed.WriteMessage($"\nIs Splined: {leader.IsSplined}");ed.WriteMessage($"\nNumber of Vertices: {leader.NumVertices}");ed.WriteMessage($"\nAnnotation: {leader.Annotation}");ed.WriteMessage("\n\nVertices:");for(inti=0;i<leader.NumVertices;i++){Point3dvertex=leader.GetVertexAt(i);ed.WriteMessage($"\n Vertex {i}: ({vertex.X:F2}, {vertex.Y:F2}, {vertex.Z:F2})");}tr.Commit();}
Example 5: Modifying Leader Vertices
using(Transactiontr=db.TransactionManager.StartTransaction()){Leaderleader=tr.GetObject(leaderId,OpenMode.ForWrite)asLeader;// Move the middle vertexif(leader.NumVertices>=3){Point3dmiddleVertex=leader.GetVertexAt(1);Point3dnewVertex=newPoint3d(middleVertex.X+5,middleVertex.Y+5,middleVertex.Z);leader.SetVertexAt(1,newVertex);leader.EvaluateLeader();}tr.Commit();}