I'm testing code from Kean:
http://through-the-interface.typepad.com/through_the_interface/2007/01/creating_an_aut.html
Everything is ok, it works great.
But I have one problem. I would like to have closed-filled arrow with my MLeader, but when I send stringname = "" or "." I'm getting error about no found key.
Anyone has got some clue for me? I googled I found nothing.
AC 2007, WinXP x86, VS2010, NET 3.5
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'~