I reported this same problem to the ADN guys and this is the response I got...
I just handled a similar case few week ago: the "Leader.Annotation" property is broken in release 2012 (it has been fixed in 2013), so you need to P/Invoke attachAnnotation from arx before being able to use EvaluateLeader.
Sorry that the code is in C#, but the conversion should be straightforward:
[DllImport("acdb18.dll",
CallingConvention = CallingConvention.ThisCall,
CharSet = CharSet.Unicode,
EntryPoint = "?attachAnnotation@AcDbLeader@@UAE?AW4ErrorStatus@Acad@@ABVAcDbObjectId@@@Z")]
private static extern ErrorStatus attachAnnotation32(IntPtr thisPtr, ref ObjectId annoId);
[DllImport("acdb18.dll",
CallingConvention = CallingConvention.ThisCall,
CharSet = CharSet.Unicode,
EntryPoint = "?attachAnnotation@AcDbLeader@@UEAA?AW4ErrorStatus@Acad@@AEBVAcDbObjectId@@@Z")]
private static extern ErrorStatus attachAnnotation64(IntPtr thisPtr, ref ObjectId annoId);
private static ErrorStatus attachAnnotation(IntPtr thisPtr, ref ObjectId annoId)
{
if (Marshal.SizeOf(IntPtr.Zero) > 4)
return attachAnnotation64(thisPtr, ref annoId);
return attachAnnotation32(thisPtr, ref annoId);
}
[CommandMethod("LeadAnnot")]
static public void LeadAnnot()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Database db = doc.Database;
Editor ed = doc.Editor;
ObjectId leaderId;
ObjectId textId;
using (Transaction Tx = db.TransactionManager.StartTransaction())
{
BlockTableRecord btr = Tx.GetObject(
db.CurrentSpaceId,
OpenMode.ForWrite)
as BlockTableRecord;
Point3d p1 = new Point3d(0, 0, 0);
Point3d p2 = new Point3d(5, 5, 0);
MText MText = new MText();
MText.SetDatabaseDefaults();
MText.SetContentsRtf("Leader Annotation");
MText.Normal = Vector3d.ZAxis;
MText.Location = p2;
textId = btr.AppendEntity(MText);
Tx.AddNewlyCreatedDBObject(MText, true);
Leader leader = new Leader();
leader.SetDatabaseDefaults();
leader.AppendVertex(p1);
leader.AppendVertex(p2);
leaderId = btr.AppendEntity(leader);
Tx.AddNewlyCreatedDBObject(leader, true);
//Leader needs to be db-resident before setting Annotation
//Nb:broken in 2012
//leader.Annotation = MText.ObjectId;
ErrorStatus es = attachAnnotation(
leader.UnmanagedObject,
ref textId);
leader.EvaluateLeader();
Tx.Commit();
}
}