Thanks for your Suggestion,
I have to select the block reference, to get its name.
I got the list of the used blocks in the active dwg by this code.
[CommandMethod("REV1")]
public void EditBlock1()
{
Document acDoc = Application.DocumentManager.MdiActiveDocument;
Editor ed = acDoc.Editor;
var acDb = HostApplicationServices.WorkingDatabase;
using (var acTrans = acDb.TransactionManager.StartTransaction())
{
var acBlockTable =
acTrans.GetObject(acDb.BlockTableId, OpenMode.ForRead) as BlockTable;
if (acBlockTable == null) return;
var acBlockTableRecord = acTrans.GetObject(acBlockTable[BlockTableRecord.ModelSpace],
OpenMode.ForRead) as BlockTableRecord;
if (acBlockTableRecord == null) return;
foreach (ObjectId id in acBlockTableRecord)
{
string blockName;
BlockReference bref = acTrans.GetObject(id, OpenMode.ForRead) as BlockReference;
if (bref != null)
{
if (bref.IsDynamicBlock)
{
BlockTableRecord br = (BlockTableRecord)acTrans.GetObject(bref.DynamicBlockTableRecord, OpenMode.ForRead);
//blockName = br.Name;
blockName = "DynamicBlock";
}
else
{
blockName = bref.Name;
}
//Debug.WriteLine("Found block reference: " + blockName);
ed.WriteMessage("\n Found block reference: {0}\n\n", blockName);
}
}
acTrans.Commit();
}
}