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

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

0 REPLIES 0
Reply
Message 1 of 1
wesbird
391 Views, 0 Replies

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

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
Windows 10 64 bit, AutoCAD (ACA, Map) 2023
0 REPLIES 0

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