[CommandMethod("00Texttomleader")]
public static void MTextToMultileader()
{
Point3d startPoint = GetPointFromUser("Set leg position");
Point3d basePoint = GetPointFromUser("Set text position");
CreateMultileader("yyyyyy", basePoint, startPoint);
}
public static Point3d GetPointFromUser(string message)
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
PromptPointOptions pickPoint = new PromptPointOptions(message);
PromptPointResult insertPoint = ed.GetPoint(pickPoint);
return insertPoint.Value;
}
public static void CreateMultileader(string content, Point3d textLocation, Point3d startPoint3D)
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
using (Transaction tr = db.TransactionManager.StartTransaction())
{
BlockTable table = tr.GetObject(db.BlockTableId, OpenMode.ForRead) as BlockTable;
BlockTableRecord btr = tr.GetObject(table[BlockTableRecord.ModelSpace], OpenMode.ForWrite) as BlockTableRecord;
MLeader leader = new MLeader();
leader.SetDatabaseDefaults();
leader.ContentType = ContentType.MTextContent;
MText mText = new MText();
mText.TextStyleId = leader.TextStyleId;
//mText.SetDatabaseDefaults();
//mText.Width = 100;
//mText.Height = 50;
mText.SetContentsRtf(content);
mText.Location = textLocation;
leader.MText = mText;
int idx = leader.AddLeaderLine(startPoint3D);
//leader.AddFirstVertex(idx, startPoint3D);
btr.AppendEntity(leader);
tr.AddNewlyCreatedDBObject(leader, true);
tr.Commit();
}
}