[CommandMethod("readBlockTable"
static public void CmdReadBlockTable()
{
Editor ed = Application.DocumentManager.
MdiActiveDocument.Editor;
// select a block reference
PromptEntityOptions peo = new PromptEntityOptions(
"Select a dynamic block reference: ");
peo.SetRejectMessage("Only block reference");
peo.AddAllowedClass(typeof(BlockReference), false);
PromptEntityResult per = ed.GetEntity(peo);
if (per.Status != PromptStatus.OK) return;
ObjectId blockRefId = per.ObjectId;
// get the database and start a transaction
Database db = Application.DocumentManager.
MdiActiveDocument.Database;
using (Transaction trans = db.
TransactionManager.StartTransaction())
{
// open the dynamic block reference
BlockReference blockRef = trans.GetObject(
blockRefId, OpenMode.ForRead) as BlockReference;
if (!blockRef.IsDynamicBlock) return;
// get the dynamic block table definition
BlockTableRecord blockDef = trans.GetObject(
blockRef.DynamicBlockTableRecord,
OpenMode.ForRead) as BlockTableRecord;
// open the extension dictionary
if (blockDef.ExtensionDictionary.IsNull) return;
DBDictionary extDic = trans.GetObject(
blockDef.ExtensionDictionary, OpenMode.ForRead)
as DBDictionary;
// open the ENHANCEDBLOCK dictionary
Autodesk.AutoCAD.Internal.DatabaseServices.EvalGraph graph =
trans.GetObject(extDic.GetAt("ACAD_ENHANCEDBLOCK"),
OpenMode.ForRead) as EvalGraph;
int[] nodeIds = graph.GetAllNodes();
foreach (uint nodeId in nodeIds)
{
// open the node ID
DBObject node = graph.GetNode(nodeId,
OpenMode.ForRead, trans);
// check is if the correct type
if (!(node is BlockPropertiesTable)) continue;
// convert the object
BlockPropertiesTable table =
node as BlockPropertiesTable;
// ok, we have the data, let's show it...
// get the number of columns
int columns = table.Columns.Count;
int currentRow = 0;
foreach (
BlockPropertiesTableRow row
in table.Rows)
{
ed.WriteMessage("\n[{0}]:\t", currentRow);
for (
int currentColumn = 0;
currentColumn < columns;
currentColumn++)
{
// get the colum value for the
// current row. May be more multiple
TypedValue[] columnValue =
row[currentColumn].AsArray();
foreach (TypedValue tpVal in columnValue)
{
ed.WriteMessage("{0}; ", tpVal.Value);
}
ed.WriteMessage("|");
}
currentRow++;
}
}
}
}