.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

why [ EvaluateLeader ] throw an exception in 2012

6 REPLIES 6
SOLVED
Reply
Message 1 of 7
JanetDavidson
806 Views, 6 Replies

why [ EvaluateLeader ] throw an exception in 2012

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

 

6 REPLIES 6
Message 2 of 7

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
Message 3 of 7
Hallex
in reply to: JanetDavidson

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
Message 4 of 7

Thanks, I got it.

Janet.

Message 5 of 7
dhaverstick
in reply to: JanetDavidson

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

    }

}

Message 6 of 7
JanetDavidson
in reply to: dhaverstick

Hi,

dhaverstick,

Thanks for update.

 

Message 7 of 7
dhaverstick
in reply to: JanetDavidson

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.

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Autodesk Design & Make Report

”Boost