關閉圖層問題
<font face="Simsun" size="2">我在自己的程序前面建立了名为 1,2,3的图层,在不同的图层绘制了不同的实体.<br/><br/>在某一步时,我想关闭图层1和2,只显示图层3的实体,请问如何用objectarx实现,谢谢</font> 遍历图层表的记录,使用AcDbLayerTableRecord 对象的<p class="signature">void setIsOff(bool off);</p><p class="signatureInEnd">关闭图层</p> //-------------------------------------------------------------------------------//将关闭层1、2,显示层3,以下内容在ARX08测试成功//多看书,这个不难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();
}
<p>再贴一个,希望对你有帮助</p><p>Adesk::Boolean SetIsOff (const char* lyrname,<br/> bool off)<br/>{<br/> AcDbLayerTable *pLyrTable;<br/> AcDbLayerTableRecord *pLyrTblRecord;<br/> <br/> AcDbDatabase *pCurDb = NULL;<br/> pCurDb = acdbHostApplicationServices()->workingDatabase();<br/> <br/> // 获得当前图形的层表<br/> pCurDb->getLayerTable(pLyrTable, AcDb::kForRead);<br/> AcDbObjectId lyrId;<br/> // 是否已经包含指定的层表记录<br/> if (!pLyrTable->has(lyrname) && !(lyrname == "*"))<br/> {<br/> pLyrTable->close();<br/> return Adesk::kFalse; <br/> }<br/> else<br/> {<br/> pLyrTable->getAt(lyrname, lyrId);<br/> }<br/> AcDbLayerTableIterator *pItr; <br/> pLyrTable->newIterator(pItr); <br/> if (lyrname == "*")<br/> {<br/> for (pItr->start(); !pItr->done(); pItr->step()) <br/> { // 遍历器记录<br/> pItr->getRecord(pLyrTblRecord, AcDb::kForWrite); <br/> pLyrTblRecord->setIsOff(off);<br/> pLyrTblRecord->close();<br/> }<br/> }<br/> else<br/> {<br/> for (pItr->start(); !pItr->done(); pItr->step()) <br/> { // 遍历器记录<br/> if(pItr->seek(lyrId) == Acad::eOk)<br/> {<br/> pItr->getRecord(pLyrTblRecord, AcDb::kForWrite); <br/> pLyrTblRecord->setIsOff(off);<br/> pLyrTblRecord->close();<br/> break;<br/> }<br/> }<br/> }<br/> delete pItr;<br/> <br/> pLyrTable->close();<br/> return Adesk::kTrue;<br/>}</p>
页:
[1]