I assume that you use PromptNestedEntityResult object to obtain user picked AttributeReference' ObjectId.
According to the document and ObjectBrowser, there is a method: PromptNestedEntityResult.GetContainers(). It looks like the one we could use to find out which blockreference object owns the picked attribute. However, I tried this method with a simple block ( a circle with a couple of attributes) without sucess: the PromptNestedEntityResult.GetContainers() returns no container at all, although the picked nested entity is correctly an attribute.
But there is still a way to get what you want: AttributeReference.OwnerId will identify the BlockReference that owns the attributereference:
The code will look like:
Document dwg = Application.DocumentManager.MdiActiveDocument;
Editor ed = dwg.Editor;
Database db = dwg.Database;
//Pick nested object - Attribute in a block
PromptNestedEntityOptions opt = new
PromptNestedEntityOptions("\nPick an attribute:");
opt.AllowNone = false;
PromptNestedEntityResult res = ed.GetNestedEntity(opt);
if (res.Status == PromptStatus.OK)
{
using (Transaction tran = db.TransactionManager.StartTransaction())
{
AttributeReference att = tran.GetObject(res.ObjectId, OpenMode.ForRead) as AttributeReference;
ed.WriteMessage("\nOwner ({0}): {1}", att.OwnerId.ToString(), att.OwnerId.ObjectClass.DxfName);
BlockReference blk = tran.GetObject(att.OwnerId, OpenMode.ForRead) as BlockReference;
ed.WriteMessage("\nPicked attribute is owned by block \"{0}\"", blk.Name);
tran.Commit();
}
}