.NET

Reply
Contributor
mabe2k11
Posts: 24
Registered: ‎03-14-2006
Message 1 of 8 (625 Views)

Leader with MText annotation

625 Views, 7 Replies
03-14-2006 08:48 AM
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();
}
}
Distinguished Contributor
cgay
Posts: 125
Registered: ‎08-02-2005
Message 2 of 8 (624 Views)

Re: Leader with MText annotation

03-14-2006 01:43 PM 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
Contributor
mabe2k11
Posts: 24
Registered: ‎03-14-2006
Message 3 of 8 (623 Views)

Re: Leader with MText annotation

03-14-2006 11:16 PM in reply to: mabe2k11
Thank you!
It works great.
Valued Contributor
McSwiller
Posts: 64
Registered: ‎11-06-2006
Message 4 of 8 (623 Views)

Re: Leader with MText annotation

08-05-2008 02:04 PM 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?
Valued Contributor
McSwiller
Posts: 64
Registered: ‎11-06-2006
Message 5 of 8 (623 Views)

Re: Leader with MText annotation

08-06-2008 11:45 AM in reply to: mabe2k11
Is anyone (else?) getting this method to work, and have it associate an annotation with a leader?
Valued Contributor
McSwiller
Posts: 64
Registered: ‎11-06-2006
Message 6 of 8 (623 Views)

Re: Leader with MText annotation

08-06-2008 02:27 PM 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?
Valued Contributor
McSwiller
Posts: 64
Registered: ‎11-06-2006
Message 7 of 8 (623 Views)

Re: Leader with MText annotation

08-08-2008 01:44 PM in reply to: mabe2k11
Solved - the Z value for vertices needs to be Zero (0).
Contributor
askrius
Posts: 24
Registered: ‎08-27-2008
Message 8 of 8 (623 Views)

Re: Leader with MText annotation

08-27-2008 01:45 PM in reply to: mabe2k11
Awesome!

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

Glad I searched the forum...
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 or visit the Installation and Licensing Forum to get help installing your software.