Hello!
I tried to draw a leader, with a MText which has an annotation with it (Like the AutoCAD QLeader).
But when I run it in AutoCAD i get the following Error:
Befehl: ATDrawQLeader
Autodesk.AutoCAD.Runtime.Exception: eNotInDatabase
bei Autodesk.AutoCAD.Runtime.Interop.ThrowExceptionForErrorStatus(Int32
errorStatus)
bei Autodesk.AutoCAD.DatabaseServices.Leader.set_Annotation(ObjectId value)
bei AcadTools.Draw_Elements.DrawQLeader() in C:\AcadTools\AcadTools\Draw Elements.cs:Zeile 117.
Can anybody tell me, what the problem is?
Here is my Code:
[CommandMethod("ATDrawQLeader")]
public void DrawQLeader()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
try
{
BlockTable bt = (BlockTable)trans.GetObject(HostApplicationServices.WorkingDatabase.BlockTableId, OpenMode.ForRead);
BlockTableRecord btr = (BlockTableRecord)trans.GetObject(HostApplicationServices.WorkingDatabase.CurrentSpaceId, OpenMode.ForWrite);
//Create a MText and add it to the BlockTableRecord
MText mtext = new MText();
mtext.Contents = "Text";
mtext.Location = new Point3d(100, 100, 0);
ObjectId mtextId = btr.AppendEntity(mtext);
trans.AddNewlyCreatedDBObject(mtext, true);
//Create a Leader
Leader leader = new Leader();
leader.AppendVertex(new Point3d(10,10,0));
leader.AppendVertex(mtext.Location);
//Make a annotation between the Leader and the MText <- it crashes here!
leader.Annotation = mtextId;
//Add the Leader to the BlockTableRecord
btr.AppendEntity(leader);
trans.AddNewlyCreatedDBObject(leader, true);
trans.Commit();
}
catch (Autodesk.AutoCAD.Runtime.Exception e)
{
ed.WriteMessage(e.ToString());
}
finally
{
trans.Dispose();
}
}