.NET

Reply
Distinguished Contributor
wesbird
Posts: 352
Registered: ‎12-05-2003
Message 1 of 1 (179 Views)

t.GetObject(db.NamedObjectsDictionaryId throw exception when no such dict exist

179 Views, 0 Replies
10-25-2005 07:48 AM
Hi,
I have simple function, ReadXrecord, which return the dictionary value if exist, null if not. what I got now, when there is no such dictionary exist, it will throw exception at
"DBDictionary WX = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);"
I've tried change ForWrite to ForRead. does not work.
I already have try .. catch. but does not work

What's wrong I am doing? I really appreciate your help.

here is my code:
[code]
public static void ReadXrecord(string strDictionaryName, string strDictionaryKey,
out ResultBuffer dataDict)
{
// debug
DDebug.WriteMessage("\n AutoCADLib_ReadXrecord start.");

Database db = HostApplicationServices.WorkingDatabase;
Transaction trans = db.TransactionManager.StartTransaction();
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;

// Get the Dictionary
dataDict=null;
DBDictionary dictWX;
try
{
DBDictionary WX = (DBDictionary)trans.GetObject(db.NamedObjectsDictionaryId, OpenMode.ForWrite);
try
{
//if it exists, just get it
dictWX = (DBDictionary)trans.GetObject(WX.GetAt(strDictionaryName), OpenMode.ForRead);
}
catch (System.Exception caught)
{
// debug
DDebug.WriteMessage("\n AutoCADLib_ReadXrecord:" + caught.ToString());
trans.Abort();
return;
}
//
Xrecord xrecWX;
try
{
xrecWX = (Xrecord)trans.GetObject(dictWX.GetAt(strDictionaryKey),OpenMode.ForRead);
}
catch (System.Exception caught)
{
// debug
DDebug.WriteMessage("\n AutoCADLib_ReadXrecord-2:" + caught.ToString());
trans.Abort();
return;
}
dataDict = xrecWX.Data;
trans.Commit();
}
catch (System.Exception caught)
{
// debug
DDebug.WriteMessage("\n AutoCADLib_ReadXrecord-3:" + caught.ToString());
trans.Abort();
}
finally { trans.Dispose(); }

// debug
DDebug.WriteMessage("\n AutoCADLib_ReadXrecord end.");
}
[/code]

here is the message it throwed:
AutoCADLib_ReadXrecord:Autodesk.AutoCAD.Runtime.Exception: eKeyNotFound
at Autodesk.AutoCAD.Runtime.Interop.ThrowExceptionForErrorStatus(Int32
errorStatus)
at Autodesk.AutoCAD.Runtime.Interop.Check(Int32 returnValue)
at Autodesk.AutoCAD.DatabaseServices.DBDictionary.GetAt(String entryName)
at RealSuiteAutoCADAdapter.AutoCADLib.ReadXrecord(String strDictionaryName,
String strDictionaryKey, ResultBuffer& dataDict) in
c:\projects\orc\...\....\....cs:line 218


Wes
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Are You Going To Be @ AU 2014? Feel free to drop by our AU topic post and share your plans, plug a class that you're teaching, or simply check out who else from the community might be in attendance. Ohh and don't forgot to stop by the Autodesk Help | Learn | Collaborate booths in the Exhibit Hall and meet our community team if you get a chance!