關閉圖層問題
我在自己的程序前面建立了名为 1,2,3的图层,在不同的图层绘制了不同的实体.在某一步时,我想关闭图层1和2,只显示图层3的实体,请问如何用objectarx实现,谢谢 遍历图层表的记录,使用AcDbLayerTableRecord 对象的void setIsOff(bool off);
关闭图层
复制代码复制代码复制代码void fun()
{
AcDbLayerTable *pLayerTable;
acdbHostApplicationServices()->workingDatabase()->getLayerTable( pLayerTable, AcDb::kForRead );
AcDbLayerTableIterator *pItr;
AcDbLayerTableRecord *pLayerTableRecord;
ACHAR *layerName;
pLayerTable->newIterator( pItr );
for ( pItr->start(); !pItr->done(); pItr->step() )
{
pItr->getRecord( pLayerTableRecord, AcDb::kForWrite );
pLayerTableRecord->getName( layerName );
if ( _tcscmp( layerName, _T("1")) == 0 || _tcscmp( layerName, _T("2")) ==0 )
{
pLayerTableRecord->setIsOff( true );
}
if ( _tcscmp( layerName, _T("3")) == 0 )
{
pLayerTableRecord->setIsOff( false );
}
pLayerTableRecord->close();
free( layerName );
}
delete pItr;
pLayerTable->close();
}
再贴一个,希望对你有帮助
Adesk::Boolean SetIsOff (const char* lyrname,
bool off)
{
AcDbLayerTable *pLyrTable;
AcDbLayerTableRecord *pLyrTblRecord;
AcDbDatabase *pCurDb = NULL;
pCurDb = acdbHostApplicationServices()->workingDatabase();
// 获得当前图形的层表
pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);
AcDbObjectId lyrId;
// 是否已经包含指定的层表记录
if (!pLyrTable->has(lyrname) && !(lyrname == "*"))
{
pLyrTable->close();
return Adesk::kFalse;
}
else
{
pLyrTable->getAt(lyrname, lyrId);
}
AcDbLayerTableIterator *pItr;
pLyrTable->newIterator(pItr);
if (lyrname == "*")
{
for (pItr->start(); !pItr->done(); pItr->step())
{ // 遍历器记录
pItr->getRecord(pLyrTblRecord, AcDb::kForWrite);
pLyrTblRecord->setIsOff(off);
pLyrTblRecord->close();
}
}
else
{
for (pItr->start(); !pItr->done(); pItr->step())
{ // 遍历器记录
if(pItr->seek(lyrId) == Acad::eOk)
{
pItr->getRecord(pLyrTblRecord, AcDb::kForWrite);
pLyrTblRecord->setIsOff(off);
pLyrTblRecord->close();
break;
}
}
}
delete pItr;
pLyrTable->close();
return Adesk::kTrue;
}
页:
[1]