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

Leader with MText annotation

7 REPLIES 7
Reply
Message 1 of 8
mabe2k11
1290 Views, 7 Replies

Leader with MText annotation

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();
}
}
7 REPLIES 7
Message 2 of 8
cgay
in reply to: mabe2k11

mabe2k,

The error 'eNotInDatabase' seems to mean that you must insert the leader into the block table first.
try switching these statements like so:

[code]
btr.AppendEntity(leader);
leader.Annotation = mtextId;
[/code]

let us know if this works
C
Message 3 of 8
mabe2k11
in reply to: mabe2k11

Thank you!
It works great.
Message 4 of 8
McSwiller
in reply to: mabe2k11

I'm trying this same methodology, and all I get back when I try to associate the annotation is a eNotApplicable error. (at the line leader.Annotation = mtext.ObjectId)
What am I doing wrong?
Message 5 of 8
McSwiller
in reply to: mabe2k11

Is anyone (else?) getting this method to work, and have it associate an annotation with a leader?
Message 6 of 8
McSwiller
in reply to: mabe2k11

It *does* work for me too, as written above in C#, but I'm working in VB.Net. -Equivalent code for each line.
I still get this error:
Autodesk.AutoCAD.Runtime.Exception: eNotApplicable
at Autodesk.AutoCAD.Runtime.Interop.ThrowExceptionForErrorStatus(Int32 errorStatus)
at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)
at Autodesk.AutoCAD.DatabaseServices.Leader.set_Annotation(ObjectId value)

Any suggestions?
Message 7 of 8
McSwiller
in reply to: mabe2k11

Solved - the Z value for vertices needs to be Zero (0).
Message 8 of 8
askrius
in reply to: mabe2k11

Awesome!

Thanks for the advice. This totally fixed a problem I was having!

Glad I searched the forum...

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