- UID
- 31500
- 积分
- 76
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2003-2-25
- 最后登录
- 1970-1-1
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
// 将快名称列表添加到树状控件中
void CDlgBlockList::AddBlocksToTree()
{
// 添加根节点
HTREEITEM hFather, hTreeItem;
hFather = m_treBlock.InsertItem("BlockTable", NULL, TVI_LAST);
// 遍历块表,如果一个块定义不包括嵌套的块,直接添加一个子节点;
// 如果一个块定义包括嵌套的块,则同时添加一个次级子节点
const char *blockName;
AcDbBlockTable *pBlockTable;
acdbHostApplicationServices()->workingDatabase()
->getBlockTable(pBlockTable, AcDb::kForRead);
// 定义块表遍历器并获得指向遍历器的指针
AcDbBlockTableIterator *pBlkTabIterator;
pBlockTable->newIterator(pBlkTabIterator);
// 遍历块表
for (pBlkTabIterator->start(); !pBlkTabIterator->done(); pBlkTabIterator->step())
{
AcDbBlockTableRecord *pBlkTabRecord;
pBlkTabIterator->getRecord(pBlkTabRecord, AcDb::kForRead);
pBlkTabRecord->getName(blockName);
// 过滤掉ModelSpace和PaperSpace(在需要的时候可以去掉这个过滤器)
if ((strcmp(blockName, "*Model_Space") == 0) | (strcmp(blockName, "*Paper_Space")== 0) |
(strcmp(blockName, "*Paper_Space0") == 0))
{
pBlockTable->close();
continue;
}
hTreeItem = m_treBlock.InsertItem(blockName, hFather, TVI_LAST);
// 如果块定义包含嵌套的块
CStringArray strArray;
int number;
if (GetNestedBlocks(pBlkTabRecord, strArray, number) == Acad::eOk)
{
// 将嵌套块的名称添加到本级的子节点中
for (int i = 0; i <= strArray.GetSize() - 1; i ++)
{
m_treBlock.InsertItem(strArray.GetAt(i), hTreeItem, TVI_LAST);
}
}
pBlkTabRecord->close();
}
delete pBlkTabIterator;
pBlockTable->close();
}
// 获得一个块中嵌套块的名称
// 如果一个块含有嵌套块,返回Acad::eOk,并且在参数中传出嵌套块名称的数组
// 如果不含嵌套块,直接返回Acad::eNotApplicable
Acad::ErrorStatus
CDlgBlockList::GetNestedBlocks(AcDbBlockTableRecord * pBlkTabRecord,
CStringArray &strArray, int &count)
{
AcDbBlockTableRecordIterator *pBlockIterator;
pBlkTabRecord->newIterator(pBlockIterator);
int i = 1;
// 遍历块表记录
for (pBlockIterator->start(); !pBlockIterator->done(); pBlockIterator->step())
{
AcDbEntity *pEntity;
pBlockIterator->getEntity(pEntity, AcDb::kForRead);
// 获得实体的类名
const char *pClassName = pEntity->isA()->name();
if (strcmp(pClassName, "AcDbBlockReference") == 0)
{
CString strName;
char *name;
AcDbBlockReference *pBlockReference;
AcDbBlockTableRecord *pBlockTableRecord;
pBlockReference = (AcDbBlockReference *)pEntity;
acdbOpenObject(pBlockTableRecord,
pBlockReference->blockTableRecord(), AcDb::kForRead);
Acad::ErrorStatus es;
es = pBlockTableRecord->getName(name);
if (es == Acad::eOk)
{
strName.Format("%s", name);
bool bEqual = false;
// 如果数组中已经存在相同的元素,就不再添加到数组中
for (int j = 0; j <= strArray.GetSize() - 1; j ++)
{
if (strName == strArray.GetAt(j))
bEqual = true;
}
if (!bEqual)
{
strArray.Add(strName);
}
}
pBlockReference->close();
pBlockTableRecord->close();
}
pEntity->close();
i ++;
}
delete pBlockIterator;
count = i; // 返回块表记录中包含的实体数
if (strArray.GetSize() != 0)
{
return Acad::eOk;
}
else
{
return Acad::eNotApplicable;
}
} |
|