.NET

.NET

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

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

185 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
Vault Pro 2014, Windows 7 64 bit, AutoCAD (ACA, Map) 2014
Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.