why [ EvaluateLeader ] throw an exception in 2012

why [ EvaluateLeader ] throw an exception in 2012

JanetDavidson
Advocate Advocate
1,155 Views
6 Replies
Message 1 of 7

why [ EvaluateLeader ] throw an exception in 2012

JanetDavidson
Advocate
Advocate

Hello, I had this leader sub in my 2010 . now I am getting error in 2012 right on  Myleader.EvaluateLeader.

Does anybody facing this ?

Janet

 

0 Likes
Accepted solutions (1)
1,156 Views
6 Replies
Replies (6)
Message 2 of 7

augusto.goncalves
Alumni
Alumni
Accepted solution

Hi,

 

This method will throw an exception if an error occur. According to the help:

 

"Returns Acad::eOk if successful. Returns Acad::eNotApplicable if the leader has no associated annotation, or Acad::eInvalidInput if the leader's annotation ID and the persistent reactor ID of the annotation did not match. In the latter case, associativity is removed."

 

Regards,

 

Augusto Goncalves

Autodesk Developer Network

Regards,



Augusto Goncalves
Twitter @augustomaia
Autodesk Developer Network
0 Likes
Message 3 of 7

Hallex
Advisor
Advisor

You have use Evaluate method  just in case your leader has an attachment (mtext, block etc)

if this leader is empty so you delete the line:

myleader.Evaluate()

not tested on 2012 though...

_____________________________________
C6309D9E0751D165D0934D0621DFF27919
0 Likes
Message 4 of 7

JanetDavidson
Advocate
Advocate

Thanks, I got it.

Janet.

0 Likes
Message 5 of 7

dhaverstick
Advocate
Advocate

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();

    }

}

0 Likes
Message 6 of 7

JanetDavidson
Advocate
Advocate

Hi,

dhaverstick,

Thanks for update.

 

0 Likes
Message 7 of 7

dhaverstick
Advocate
Advocate

No problem. I found the best way around this whole situation is to use a MLeader object instead of a Leader object. You can still attach MText to it but without the hassle.

0 Likes