.NET

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

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

168 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
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.