- UID
- 287627
- 积分
- 91
- 精华
- 贡献
-
- 威望
-
- 活跃度
-
- D豆
-
- 在线时间
- 小时
- 注册时间
- 2005-7-3
- 最后登录
- 1970-1-1
|
发表于 2006-11-1 09:33:07
|
显示全部楼层
现成的代码
void test()
{
// 得到层ID
AcDbObjectId layerId;
AcDbLayerTable *pLayerTbl = NULL;
if (acdbHostApplicationServices()->workingDatabase()
->getLayerTable(pLayerTbl, AcDb::kForRead) != Acad::eOk)
return;
if (pLayerTbl->getAt("0", layerId) != Acad::eOk)
{
pLayerTbl->close();
return;
}
pLayerTbl->close();
// 打开块表进行操作
Acad::ErrorStatus es;
AcDbBlockTable *pBlockTable = NULL;
es = acdbHostApplicationServices()->workingDatabase()
->getSymbolTable(pBlockTable, AcDb::kForRead);
if (es != Acad::eOk) return;
AcDbBlockTableIterator *pBlkIter = NULL;
if (pBlockTable->newIterator(pBlkIter) != Acad::eOk)
{
pBlockTable->close();
return;
}
pBlockTable->close();
// 遍历所有块表记录,找出插入快,设置新层
AcDbBlockTableRecord *pRecord = NULL;
AcDbBlockTableRecordIterator *pRcdIter = NULL;
AcDbEntity *pEnt = NULL;
AcDbObjectIdArray Ids;
for (; !pBlkIter->done(); pBlkIter->step())
{
if (pBlkIter->getRecord(pRecord, AcDb::kForWrite) != Acad::eOk)
{
continue;
}
// 判断是否是插入块
if (pRecord->getBlockReferenceIds(Ids) != Acad::eOk || Ids.length() == 0)
{
pRecord->close();
continue;
}
if (pRecord->newIterator(pRcdIter) != Acad::eOk)
{
pRecord->close();
continue;
}
// 遍历该块表记录,设置新层
for (; !pRcdIter->done(); pRcdIter->step())
{
if (pRcdIter->getEntity(pEnt, AcDb::kForWrite) != Acad::eOk)
{
continue;
}
pEnt->setLayer(layerId);
pEnt->close();
}
delete pRcdIter;
pRcdIter = NULL;
pRecord->close();
}
delete pBlkIter;
pBlkIter = NULL;
acDocManager->sendStringToExecute(acDocManager->curDocument(), "regen ");
} |
|