private bool FindTextsInDrawing(dynamic app, dynamic acDoc, dynamic modelSpace)
{
try
{
dynamic count = CallFunc((object)app, () => modelSpace.Count);
for (int i = 0; i < (int)count; i++)
{
dynamic en = CallFunc((object)app, () => modelSpace.Item(i));
dynamic className = CallFunc((object)app, () => en.ObjectName);
if (className == "AcDbMText")
{
dynamic str = CallFunc((object)app, () => en.TextString);
ListTextItems.Add(new CFragment(str, DataType.MText));
}
else if (className == "AcDbText")
{
dynamic str = CallFunc((object)app, () => en.TextString);
ListTextItems.Add(new CFragment(str, DataType.DBText));
}
else if (className == "AcDbTable")
{
dynamic rowsCount = CallFunc((object)app, () => en.Rows);
dynamic columnsCount = CallFunc((object)app, () => en.Columns);
for (int row = 0; row < rowsCount; row++)
for (int col = 0; col < columnsCount; col++)
{
dynamic str = CallFunc((object)app, () => en.GetCellValue(row, col));
if (!String.IsNullOrEmpty(str))
{
ListTextItems.Add(new CFragment(str, DataType.Table));
}
}
}
else if (className == "AcDbMLeader")
{
dynamic str = CallFunc((object)app, () => en.TextString);
ListTextItems.Add(new CFragment(str, DataType.MLeader));
}
else if (className == "AcDbBlockReference")
{
dynamic blockHasAttributes = CallFunc((object)app, () => en.HasAttributes);
if (blockHasAttributes)
{
// Выборка текстов всех атрибутов текущего блока
dynamic attributeCollection = CallFunc((object)app, () => en.GetAttributes());
foreach (dynamic att in attributeCollection)
{
dynamic bVisible = CallFunc((object)app, () => att.Visible);
if (bVisible)
{
dynamic str = CallFunc((object)app, () => att.TextString);
ListTextItems.Add(new CFragment(str, DataType.AttributeReference));
}
}
}
dynamic blockReferenceName = CallFunc((object)app, () => en.Name);
dynamic blocks = CallFunc((object)app, () => acDoc.Blocks);
dynamic blocksCount = CallFunc((object)app, () => blocks.Count);
for (int i1 = 0; i1 < (int)blocksCount; i1++)
{
dynamic block = CallFunc((object)app, () => blocks.Item(i1));
dynamic blockName = CallFunc((object)app, () => block.Name);
if (blockName == blockReferenceName)
{
// Поиск текстов всех элементов, входящих в текущий блок
if (!FindTextsInDrawing(app, acDoc, block)) return false;
break;
}
}