.NET

Reply
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 1 of 7 (379 Views)
Accepted Solution

why [ EvaluateLeader ] throw an exception in 2012

379 Views, 6 Replies
12-05-2011 08:33 PM

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

 

ADN Support Specialist
augusto.goncalves
Posts: 312
Registered: ‎04-30-2009
Message 2 of 7 (361 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

12-08-2011 06:28 AM in reply to: JanetDavidson

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
Autodesk Developer Network
*Expert Elite*
Hallex
Posts: 1,569
Registered: ‎10-08-2008
Message 3 of 7 (350 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

12-08-2011 08:52 AM 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
Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 4 of 7 (330 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

12-13-2011 07:03 PM in reply to: augusto.goncalves

Thanks, I got it.

Janet.

Contributor
dhaverstick
Posts: 22
Registered: ‎01-12-2004
Message 5 of 7 (237 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

06-19-2012 04:28 AM 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();

    }

}

Distinguished Contributor
JanetDavidson
Posts: 139
Registered: ‎08-23-2011
Message 6 of 7 (211 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

06-27-2012 06:59 PM in reply to: dhaverstick

Hi,

dhaverstick,

Thanks for update.

 

Contributor
dhaverstick
Posts: 22
Registered: ‎01-12-2004
Message 7 of 7 (198 Views)

Re: why [ EvaluateLeader ] throw an exception in 2012

06-28-2012 04:21 AM 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.

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community