Hi all,
Question, Is it possible to update values stored in an xrecord. If not what is the best aproche my goal?
Kind regards,
Irvin
Might be a bit late, but here's what I use for a entity extension Dictionary, you will need to call it from within a transaction for it to work. Hope it helps
/// <summary>
/// Add Extension Dictionary Data to the passed database object id
/// </summary>
/// <remarks>
/// </remarks>
/// <param name="Buf">ResultBuffer to add as Xrecord to the db object's EDD</param>
/// <param name="ObjId">object to add EDD too</param>
/// <param name="DataKey">data key to use in the EDD</param>
public static void EDDAdd (ref ResultBuffer Buf, ObjectId ObjId, string DataKey)
{
Database db = HostApplicationServices.WorkingDatabase;
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
Debug.Assert(db.TransactionManager.NumberOfActiveTransactions > 0, "No transaction to link to");
try
{
SymbolUtilityServices.ValidateSymbolName(DataKey, false); //validates the name is acceptable for the Dictionary, if not throws exception
DBObject DBObj = (DBObject)db.TransactionManager.GetObject(ObjId, OpenMode.ForWrite);
if (DBObj.ExtensionDictionary.IsNull)
{
DBObj.CreateExtensionDictionary();
}
DBDictionary ExtDic = (DBDictionary)db.TransactionManager.GetObject(DBObj.ExtensionDictionary, OpenMode.ForWrite); //get entities extension dictionary
if (ExtDic.Contains(DataKey))
{
ObjectId XRecId = ExtDic.GetAt(DataKey);
Xrecord myXrecord = default(Xrecord);
myXrecord = (Xrecord)db.TransactionManager.GetObject(XRecId, OpenMode.ForWrite);
myXrecord.Data = Buf;
}
else
{
Xrecord myXrecord = new Xrecord();
myXrecord.Data = Buf;
ExtDic.SetAt(DataKey, myXrecord);
db.TransactionManager.AddNewlyCreatedDBObject(myXrecord, true);
}
}
catch (Exception e) //Autodesk.AutoCAD.Runtime.Exception
{
ed.WriteMessage("Error: DwgData.EEDAdd - " + e.Message);
}
}