Hi,
I am hoping someone can help me with what I can only assume is something easy but stumps me:
I have add an xrecord to the extension data of several entities. In this instance Polylines. The record name is "MyData".
All I want to do is get all of these items using LINQ if possible. I am sure I have seen it done in an example skipped over long ago, but not sure.
Using tr As Transaction = db.TransactionManager.StartTransaction()
Dim bt As BlockTable = tr.GetObject(db.BlockTableId, OpenMode.ForWrite)
Dim acBlkTblRec As BlockTableRecord = tr.GetObject(bt(BlockTableRecord.ModelSpace), OpenMode.ForWrite)
Dim b As IEnumerable(Of ObjectId) = acBlkTblRec.Cast(Of ObjectId)()
' This works!, but i still have to iterate to find the record name
Dim testRes1 As List(Of ObjectId) = (From id In b
Where Not (CType(tr.GetObject(id, OpenMode.ForRead), ntity).ExtensionDictionary.IsNull)
Select id).ToList
' There must be a way to convert this into the extension dictionary and then see if the xRecord name exists??
Dim testRes1 As List(Of ObjectId) = (From id In b
Where Not (CType(tr.GetObject(id, OpenMode.ForRead), Entity).ExtensionDictionary.IsNull)
Select xRec Where( TryCast(tr.GetObject(id, OpenMode.ForRead), ExtensionDictionary).Contains("MyData").ToList
End using
How do I create the DBDictionary I need to use it in the LINQ function??
Solved! Go to Solution.
Solved by _gile. Go to Solution.
Solved by _gile. Go to Solution.
Hi,
Here's a way using an anonymous type written in "method syntax".
static Dictionary<ObjectId, ResultBuffer> GetMyXrecordData(Database db)
{
using (var tr = db.TransactionManager.StartTransaction())
{
return
((BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead))
.Cast<ObjectId>()
.Select(id => (Entity)tr.GetObject(id, OpenMode.ForRead))
.Where(entity => !entity.ExtensionDictionary.IsNull)
.Select(entity => new
{
entity.ObjectId,
XDictionary = (DBDictionary)tr.GetObject(entity.ExtensionDictionary, OpenMode.ForRead)
})
.Where(pair => pair.XDictionary.Contains("MyData"))
.ToDictionary(
pair => pair.ObjectId,
pair => ((Xrecord)tr.GetObject(pair.XDictionary.GetAt("MyData"), OpenMode.ForRead)).Data);
}
}
Oops!... I read the request to fast. Here's a reply which is closer to your needs.
using (var tr = db.TransactionManager.StartTransaction())
{
var testRes1 =
((BlockTableRecord)tr.GetObject(SymbolUtilityServices.GetBlockModelSpaceId(db), OpenMode.ForRead))
.Cast<ObjectId>()
.Select(id => (Entity)tr.GetObject(id, OpenMode.ForRead))
.Where(entity => !entity.ExtensionDictionary.IsNull)
.Where(entity => ((DBDictionary)tr.GetObject(entity.ExtensionDictionary, OpenMode.ForRead)).Contains("MyData"))
.Select(entity => entity.ObjectId)
.ToList();
}
Mate.... what can I say. I hope you are somewhere in this world knowing I am raising a cold beer to you tonight!
Thank you _gile. I was trying to cast the entity in my attempt and just could not get the sequence right.
You sir are a gentleman.
Can't find what you're looking for? Ask the community or share your knowledge.