Here is working example tested on A2010
{code}
[CommandMethod("mldf")]
public void MleaderTest()
{
Document doc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
Matrix3d ucs = ed.CurrentUserCoordinateSystem;
object dimld= Autodesk.AutoCAD.ApplicationServices.Application.GetSystemVariable("dimldrblk");
using (Transaction tr = db.TransactionManager.StartTransaction())
{
try
{
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimldrblk", ".");
Point3d arrowPoint = ed.GetPoint("\nPick a point for the arrowhead: ").Value;
PromptPointOptions pto = new PromptPointOptions("\nPick a point for text: ");
pto.UseBasePoint = true;
pto.UseDashedLine = true;
pto.BasePoint = arrowPoint;
Point3d symbolPoint = ed.GetPoint(pto).Value;
Vector3d vec;
if (arrowPoint.X <= symbolPoint.X)
{
vec = new Vector3d(1, 0, 0);
}
else
{
vec = new Vector3d(-1, 0, 0);
}
BlockTableRecord btr = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
double th = db.Dimtxt;
MText mtxt = new MText();
mtxt.SetDatabaseDefaults();
mtxt.Attachment = vec == new Vector3d(1, 0, 0) ? AttachmentPoint.MiddleLeft : AttachmentPoint.MiddleRight;
mtxt.TextHeight = th;
mtxt.Width = 0.0;
mtxt.Contents = "Line 1\\PLine2";
MLeader mldr = new MLeader();
mldr.LeaderLineType = LeaderType.StraightLeader;
/* --- add other properties here --- */
mldr.AddLeaderLine(arrowPoint);
mldr.AddFirstVertex(0, arrowPoint);
mldr.AddFirstVertex(1, symbolPoint);
mldr.ArrowSymbolId = db.Dimldrblk;
DBDictionary dict = (DBDictionary)tr.GetObject(db.MLeaderStyleDictionaryId, OpenMode.ForRead);
ObjectId mlstyleid = dict.GetAt("Standard");
mldr.MLeaderStyle = mlstyleid;
mldr.ContentType = ContentType.MTextContent;
mldr.MText = mtxt;
mldr.TextLocation = symbolPoint;
mldr.SetDogleg(0, vec);
mldr.LandingGap = th/4;
mldr.DoglegLength = th;
btr.AppendEntity(mldr);
tr.AddNewlyCreatedDBObject(mldr, true);
tr.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception ex)
{
ed.WriteMessage(ex.Message + "\n" + ex.StackTrace);
}
finally
{
Autodesk.AutoCAD.ApplicationServices.Application.SetSystemVariable("dimldrblk", dimld);
}
}
}
{code}
~'J'~
_____________________________________
C6309D9E0751D165D0934D0621DFF27919