Please someone help me understanding this bizarre behavior with modifying XData. I have a list of ObjectIds, I want to modify the XData for all the entities with those ObjectIds. This is where I am having trouble, to modify the XData I loop through the list of object ids, open the corresponding entity inside a transaction change the XData for each entity but XData is not getting changed and also I am not seeing exceptions or error.
To make things complicated if I use the following code(copied from a different question in this forum) it works. I verified that object ids are same, only difference here I select a single entity from the drawing. I also tried passing my ObjectId as parameter to the following function instead of selecting an entity and it wont work.
Does anyone saw this kind of behavior before or am I missing very simple and obvious.
Thanks in advance.
Tik.
<code>
public void PutXData()
{
Document doc = Application.DocumentManager.MdiActiveDocument;
Editor ed = doc.Editor;
Database db = doc.Database;
var resEnt = ed.GetEntity("Select a Entity");
if (resEnt.Status == PromptStatus.OK)
{
using (var tr = db.TransactionManager.StartTransaction())
{
Entity ent = tr.GetObject(resEnt.ObjectId, OpenMode.ForWrite) as Entity;
var rb = ent.GetXDataForApplication("AQME");
//List<TypedValue> values = rb.AsArray().ToList<TypedValue>();
//values[1] = new TypedValue(1000, "value" + values.Count.ToString());
List<TypedValue> DataArray = new List<TypedValue>();
DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataRegAppName, "MyApp")); //0
DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "1010-BLACK"));//1
DataArray.Add(new TypedValue((int)DxfCode.ExtendedDataAsciiString, "1010-BLACK Description"));//2
ent.XData = new ResultBuffer(DataArray.ToArray());
tr.Commit();
}
}
}
</code>