/// <summary>
/// Add a record to the named object dictionary. If the dictionary doesn't exist, create it
/// </summary>
/// <param name="dictionaryName"></param>
/// <param name="key"></param>
/// <param name="data"></param>
public static void AddXrecordToNamedDictionary(string dictionaryName, string key, ResultBuffer data)
{
if (Active.Document == null) return;
try
{
using (Document.LockDocument())
{
using (Transaction tr = Active.Document.TransactionManager.StartTransaction())
{
DBDictionary nod = tr.GetObject(Active.Database.NamedObjectsDictionaryId,
OpenMode.ForWrite) as DBDictionary;
if (nod == null) return;
DBDictionary myDbDictionary
= new DBDictionary
(); if (nod.Contains(dictionaryName))
{
// set the dictionary
myDbDictionary = (DBDictionary)tr.GetObject(nod.GetAt(dictionaryName), OpenMode.ForWrite);
}
else
{
// finish creating the dictionary
nod.SetAt(dictionaryName, myDbDictionary);
tr.AddNewlyCreatedDBObject(myDbDictionary, true);
}
if (myDbDictionary.Contains(key))
{
// edit the existing xrecord
var myXRec = (Xrecord)tr.GetObject(myDbDictionary.GetAt(key), OpenMode.ForWrite);
myXRec.Data = data;
}
else
{
// add the xrecord
Xrecord newXRec
= new Xrecord
() { Data
= data
}; myDbDictionary.SetAt(key, newXRec);
tr.AddNewlyCreatedDBObject(newXRec, true);
}
tr.Commit();
}
}
}
catch (Exception e)
{
AID_Application.HandleError(e);
}
}