|
[code]static void AddMleader(Point3d startPoint, Point3d endPoint, string textContents, double textWidth, double textHeight)
{
var doc = Application.DocumentManager.MdiActiveDocument;
var db = doc.Database;
var ed = doc.Editor;
using (var tr = db.TransactionManager.StartTransaction())
{
var mleader = new MLeader();
mleader.SetDatabaseDefaults();
mleader.ContentType = ContentType.MTextContent;
int index = mleader.AddLeader();
mleader.AddLeaderLine(index);
mleader.AddFirstVertex(index, startPoint);
mleader.AddLastVertex(index, endPoint);
MText mtext = new MText();
mtext.SetDatabaseDefaults();
mtext.Width = textWidth;
mtext.Height = textHeight;
mtext.Contents = textContents;
mleader.MText = mtext;
mtext.Location = mleader.TextLocation;
if (endPoint.X < startPoint.X)
{
var offset = (mleader.DoglegLength + mleader.LandingGap) * 2 + mtext.ActualWidth;
mleader.MoveMLeader(Vector3d.XAxis * -offset, MoveType.MoveContentAndDoglegPoints);
}
var cSpace = (BlockTableRecord)tr.GetObject(db.CurrentSpaceId, OpenMode.ForWrite);
cSpace.AppendEntity(mleader);
tr.AddNewlyCreatedDBObject(mleader, true);
tr.Commit();
}
}[/code] |
|