public void FindTextsInDrawing()
{
try
{
ListNotes.Clear();
// Get the current document and database, and start a transaction
Document acDoc = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
MdiActiveDocument;
Database acCurDb = acDoc.Database;
// Get the current document editor
Editor ed = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.
MdiActiveDocument.Editor;
using (Transaction acTrans = acCurDb.TransactionManager.StartTransaction())
{
// Open the Block table record for read
BlockTable acBlkTbl;
acBlkTbl = acTrans.GetObject(acCurDb.BlockTableId,
OpenMode.ForRead) as BlockTable;
// Open the Block table record Model space for read
BlockTableRecord acBlkTblRec;
acBlkTblRec = acTrans.GetObject(acBlkTbl[BlockTableRecord.ModelSpace],
OpenMode.ForRead) as BlockTableRecord;
// Step through each object in Model space
foreach (ObjectId acObjId in acBlkTblRec)
{
Entity en = acTrans.GetObject(acObjId, OpenMode.ForRead) as Entity;
if (en != null)
{
if (en.GetType() == typeof(DBText))
{
string str = ((DBText)en).TextString;
ListNotes.Add(new CNote(str, acObjId, DataType.DBText));
}
else if (en.GetType() == typeof(MText))
{
string str = ((MText)en).Contents;
ListNotes.Add(new CNote(str, acObjId, DataType.MText));
}
else if (en.GetType() == typeof(Table))
{
Autodesk.AutoCAD.DatabaseServices.Table tbl = (Table)en;
for (int row = 0; row < tbl.Rows.Count; row++)
for (int col = 0; col < tbl.Columns.Count; col++)
{
string str = tbl.Cells[row, col].TextString;
if (!String.IsNullOrEmpty(str))
ListNotes.Add(new CNote(str, acObjId, DataType.Table, row, col));
}
}
else if (en.GetType() == typeof(BlockReference))
{
//int i = 1;
}
}
}
}
}
catch (System.Exception e)
{
Editor acDocEd = Autodesk.AutoCAD.ApplicationServices.Application.DocumentManager.MdiActiveDocument.Editor;
acDocEd.WriteMessage(String.Format("Ошибка. {0}{1}" + Environment.NewLine, e.Message, e.StackTrace));
}
}