| name | acad-mleaders |
| description | Multileaders — leader lines, MText/Block content, dogleg/landing, MLeaderStyle |
AutoCAD Multileaders (MLeader)
Use this skill when creating or modifying multileader objects - leaders with text, block, or tolerance content.
MLeader Structure
MLeader
├── Leader 0
│ ├── LeaderLine 0 (vertices: first → ... → last/arrow)
│ └── LeaderLine 1
├── Leader 1
│ └── LeaderLine 0
└── Content (MText, Block, or Tolerance - shared across all leaders)
An MLeader contains one or more Leaders (collections of leader lines pointing to the same content side). Each Leader contains one or more LeaderLines, each with multiple Vertices. The first vertex is the landing/connection point near content; the last vertex is the arrow tip.
Creating an MLeader with MText Content
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(
db.CurrentSpaceId, OpenMode.ForWrite);
MLeader mleader = new MLeader();
mleader.SetDatabaseDefaults();
mleader.ContentType = ContentType.MTextContent;
MText mt = new MText();
mt.Contents = "Label Text";
mt.TextHeight = 2.5;
mleader.MText = mt;
int leaderIdx = mleader.AddLeader();
int lineIdx = mleader.AddLeaderLine(leaderIdx);
mleader.AddFirstVertex(lineIdx, new Point3d(200, 200, 0));
mleader.AddLastVertex(lineIdx, new Point3d(100, 100, 0));
mleader.TextLocation = new Point3d(210, 200, 0);
btr.AppendEntity(mleader);
tr.AddNewlyCreatedDBObject(mleader, true);
tr.Commit();
}
Creating an MLeader with Block Content
MLeader mleader = new MLeader();
mleader.SetDatabaseDefaults();
mleader.ContentType = ContentType.BlockContent;
mleader.BlockContentId = blockDefId;
mleader.BlockPosition = new Point3d(200, 200, 0);
mleader.BlockScale = new Scale3d(1.0);
mleader.BlockRotation = 0.0;
mleader.BlockColor = Color.FromColorIndex(ColorMethod.ByLayer, 256);
mleader.BlockConnectionType = BlockConnectionType.ConnectExtents;
int leaderIdx = mleader.AddLeader();
int lineIdx = mleader.AddLeaderLine(leaderIdx);
mleader.AddFirstVertex(lineIdx, new Point3d(200, 200, 0));
mleader.AddLastVertex(lineIdx, new Point3d(100, 100, 0));
Leader and LeaderLine Management
int leaderIdx = mleader.AddLeader();
int lineIdx = mleader.AddLeaderLine(leaderIdx);
ArrayList leaderIndexes = mleader.GetLeaderIndexes();
ArrayList lineIndexes = mleader.GetLeaderLineIndexes(leaderIdx);
int parentLeader = mleader.GetLeaderIndex(lineIdx);
mleader.RemoveLeaderLine(lineIdx);
mleader.RemoveLeader(leaderIdx);
Vertex Management
mleader.AddFirstVertex(lineIdx, connectionPoint);
mleader.AddLastVertex(lineIdx, arrowPoint);
Point3d first = mleader.GetFirstVertex(lineIdx);
Point3d last = mleader.GetLastVertex(lineIdx);
mleader.SetFirstVertex(lineIdx, newPoint);
mleader.SetLastVertex(lineIdx, newPoint);
int count = mleader.VerticesCount(lineIdx);
Point3d pt = mleader.GetVertex(lineIdx, 1);
mleader.SetVertex(lineIdx, 1, newPoint);
mleader.RemoveFirstVertex(lineIdx);
mleader.RemoveLastVertex(lineIdx);
Per-Leader and Per-Line Overrides
mleader.SetDogleg(leaderIdx, new Vector3d(1, 0, 0));
Vector3d dogDir = mleader.GetDogleg(leaderIdx);
mleader.SetDoglegLength(leaderIdx, 5.0);
double dogLen = mleader.GetDoglegLength(leaderIdx);
mleader.SetLeaderLineType(lineIdx, LeaderType.SplineLeader);
mleader.SetLeaderLineColor(lineIdx, Color.FromColorIndex(ColorMethod.ByAci, 1));
mleader.SetLeaderLineWeight(lineIdx, LineWeight.LineWeight050);
mleader.SetArrowSymbolId(lineIdx, arrowBlockId);
mleader.SetArrowSize(lineIdx, 3.0);
LeaderType lt = mleader.GetLeaderLineType(lineIdx);
Color lc = mleader.GetLeaderLineColor(lineIdx);
Text Attachment (per direction)
mleader.SetTextAttachmentType(
TextAttachmentType.AttachmentMiddle,
LeaderDirectionType.LeftLeader);
TextAttachmentType att = mleader.GetTextAttachmentType(
LeaderDirectionType.RightLeader);
Block Attributes
AttributeReference attRef = mleader.GetBlockAttribute(attDefId);
string val = attRef.TextString;
attRef.TextString = "New Value";
mleader.SetBlockAttribute(attDefId, attRef);
Movement
mleader.MoveMLeader(new Vector3d(50, 50, 0), MoveType.MoveAllPoints);
MoveType enum: MoveAllPoints=0, MoveAllExceptArrowHeaderPoints=1, MoveContentAndDoglegPoints=2
MLeaderStyle
MLeaderStyle style = new MLeaderStyle();
style.Name = "My Leader Style";
style.ContentType = ContentType.MTextContent;
style.TextHeight = 2.5;
style.TextStyleId = textStyleId;
style.TextColor = Color.FromColorIndex(ColorMethod.ByLayer, 256);
style.TextAlignmentType = TextAlignmentType.LeftAlignment;
style.TextAlignAlwaysLeft = false;
style.TextAngleType = TextAngleType.HorizontalAngle;
style.EnableFrameText = false;
style.LeaderLineType = LeaderType.StraightLeader;
style.LeaderLineColor = Color.FromColorIndex(ColorMethod.ByBlock, 0);
style.ArrowSymbolId = ObjectId.Null;
style.ArrowSize = 3.0;
style.EnableDogleg = true;
style.DoglegLength = 8.0;
style.EnableLanding = true;
style.LandingGap = 2.0;
style.ExtendLeaderToText = true;
style.BlockId = blockId;
style.BlockConnectionType = BlockConnectionType.ConnectExtents;
style.BlockScale = new Scale3d(1.0);
style.EnableBlockScale = false;
style.EnableBlockRotation = false;
style.Scale = 1.0;
style.BreakSize = 2.0;
style.MaxLeaderSegmentsPoints = 2;
style.FirstSegmentAngleConstraint = AngleConstraint.DegreesAny;
style.SecondSegmentAngleConstraint = AngleConstraint.DegreesAny;
style.DrawLeaderOrderType = DrawLeaderOrderType.DrawLeaderHeadFirst;
style.DrawMLeaderOrderType = DrawMLeaderOrderType.DrawContentFirst;
style.SetTextAttachmentType(
TextAttachmentType.AttachmentMiddleOfTop, LeaderDirectionType.LeftLeader);
style.SetTextAttachmentType(
TextAttachmentType.AttachmentMiddleOfTop, LeaderDirectionType.RightLeader);
style.TextAttachmentDirection = TextAttachmentDirection.AttachmentHorizontal;
ObjectId styleId = style.PostMLeaderStyleToDb(db, "My Leader Style");
tr.AddNewlyCreatedDBObject(style, true);
Enums
TextAttachmentType: AttachmentTopOfTop=0, AttachmentMiddleOfTop=1, AttachmentMiddle=2, AttachmentMiddleOfBottom=3, AttachmentBottomOfBottom=4, AttachmentBottomLine=5, AttachmentBottomOfTopLine=6, AttachmentBottomOfTop=7, AttachmentAllLine=8, AttachmentCenter=9, AttachmentLinedCenter=10
LeaderDirectionType: UnknownLeader=0, LeftLeader=1, RightLeader=2, TopLeader=3, BottomLeader=4
AngleConstraint: DegreesAny=0, Degrees015=1, Degrees030=2, Degrees045=3, Degrees060=4, Degrees090=6, DegreesHorz=12
DrawLeaderOrderType: DrawLeaderHeadFirst=0, DrawLeaderTailFirst=1
DrawMLeaderOrderType: DrawContentFirst=0, DrawLeaderFirst=1
Legacy Leader Class
The OARX guide documents the older Leader class (not MLeader). Prefer MLeader for new code. Use Leader only when working with legacy drawings that contain it.
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(
db.CurrentSpaceId, OpenMode.ForWrite);
Leader leader = new Leader();
leader.SetDatabaseDefaults();
leader.AppendVertex(new Point3d(100, 100, 0));
leader.AppendVertex(new Point3d(200, 150, 0));
leader.AppendVertex(new Point3d(250, 150, 0));
leader.HasArrowHead = true;
leader.IsSplined = false;
btr.AppendEntity(leader);
tr.AddNewlyCreatedDBObject(leader, true);
MText mt = new MText();
mt.Location = new Point3d(252, 150, 0);
mt.Contents = "Leader Text";
mt.TextHeight = 2.5;
btr.AppendEntity(mt);
tr.AddNewlyCreatedDBObject(mt, true);
leader.Annotation = mt.ObjectId;
leader.EvaluateLeader();
tr.Commit();
}
Gotchas
- Leader/line indexes are NOT sequential integers - always use
GetLeaderIndexes() and GetLeaderLineIndexes() to get valid indexes
- First vertex = connection point near content; Last vertex = arrow tip (opposite of what you might expect)
AddLeaderLine(Point3d) adds a line to a default leader; AddLeaderLine(int leaderIndex) adds to a specific leader - different signatures do different things
- Setting
MText property replaces the content object entirely; modify the existing MText object for incremental changes
- Per-line overrides (color, weight, arrow) only take effect if they differ from the MLeader's default properties
MLeaderStyle must be posted to the database with PostMLeaderStyleToDb() before it can be assigned to an MLeader
MoveType.MoveAllExceptArrowHeaderPoints keeps arrow tips fixed while moving content - useful for repositioning text without changing what the leader points to
TextAttachmentType and direction interact: horizontal leaders use top/middle/bottom attachment; vertical leaders use center/lined attachment
Related Skills
acad-mtext — MText as MLeader text content
acad-blocks — block references as MLeader block content
acad-geometry — Point3d for leader vertices and attachment points