Here is another sample, gets the object ids of the Entities in a selection set with
XData containing a specific value, using our new LinQ enabled Resultbuffer
[CommandMethod("test")]
static public void test()
{
Editor ed = Application.DocumentManager.MdiActiveDocument.Editor;
TypedValue[] values = new TypedValue[]
{
new TypedValue((short)DxfCode.Start, "LINE") ,
new TypedValue((short)DxfCode.XDataStart) ,
new TypedValue((short)DxfCode.ExtendedDataRegAppName, "Dan")
};
SelectionFilter filter = new SelectionFilter(values);
PromptSelectionOptions selopts = new PromptSelectionOptions();
selopts.MessageForAdding = "Select";
selopts.AllowDuplicates = false;
PromptSelectionResult result = ed.GetSelection(selopts, filter);
if (result.Status == PromptStatus.OK)
{
ObjectId[] idarray = result.Value.GetObjectIds();
List<ObjectId> rlist = new List<ObjectId>();
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm =
Application.DocumentManager.MdiActiveDocument.Database.TransactionManager;
//our filter
TypedValue Xdatafilter = new TypedValue((int)DxfCode.ExtendedDataAsciiString, "a");
Transaction tr = tm.StartTransaction();
try
{
foreach (ObjectId id1 in idarray)
{
Entity ent = (Entity)tm.GetObject(id1, OpenMode.ForRead, true);
ResultBuffer xRb = ent.XData;
//using our Extension method here
var query = xRb.Where(p => p.Equals(Xdatafilter));
//or
// a LinQ Style query
//var query = from f in xRb
// where f == Xdatafilter
// select f;
if (query.Count() != 0)
{
rlist.Add(ent.ObjectId);
}
}
//using our Extension method here
rlist.ForEach(p => ed.WriteMessage("\n" + p.ToString()));
}
catch (System.Exception ex)
{
ed.WriteMessage(ex.Message);
}
finally
{
tr.Dispose();
}
}
}