Thanks Andrey, there is a lot of good information there and it was a big help!
Here is my solution
// Get the current document
Editor acDocEd = Application.DocumentManager.MdiActiveDocument.Editor;
// Get the PickFirst selection set
// PromptSelectionResult acSSPrompt;
TypedValue[] tvs =
new TypedValue[2]
{
new TypedValue((int)DxfCode.LayerName, "TITL-BLOK"),
new TypedValue((int)DxfCode.Start, "INSERT")
};
SelectionFilter selctfltr =
new SelectionFilter(tvs);
PromptSelectionResult psr =
acDocEd.SelectAll(selctfltr);
if (psr.Value.Count == 0)
{
System.Windows.Forms.MessageBox.Show("Missing Title block - I cannot read the Name Attribute Definition");
return null;
}
Autodesk.AutoCAD.EditorInput.SelectedObject titleblock = (Autodesk.AutoCAD.EditorInput.SelectedObject)psr.Value[0];
Autodesk.AutoCAD.ApplicationServices.DocumentCollection docCol;
Autodesk.AutoCAD.ApplicationServices.Document doc;
Autodesk.AutoCAD.DatabaseServices.TransactionManager tm;
docCol = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager;
doc = docCol.MdiActiveDocument;
tm = doc.Database.TransactionManager;
Transaction tr = tm.StartTransaction();
using (tr)
{
for (int i = 0; i < psr.Value.Count; i++)
{
SelectedObject o = psr.Value[i];
if (o.ObjectId.ObjectClass == RXClass.GetClass(typeof(BlockReference)))
{
BlockReference obj =
(BlockReference)tm.GetObject(o.ObjectId, OpenMode.ForRead);
// get its attribute collection
// iterate through the attributes
foreach (ObjectId attRefID in obj.AttributeCollection)
{
AttributeReference attref = (AttributeReference)tm.GetObject(attRefID, OpenMode.ForRead, false);
if (attref.Tag == "NAME")
{
return attref.TextString;
}
}
}
}
}