lgq19851005 发表于 2009-5-12 18:54:00

關閉圖層問題

<font face="Simsun" size="2">我在自己的程序前面建立了名为 1,2,3的图层,在不同的图层绘制了不同的实体.<br/><br/>在某一步时,我想关闭图层1和2,只显示图层3的实体,请问如何用objectarx实现,谢谢</font>

松竹 发表于 2009-5-16 09:17:00

遍历图层表的记录,使用AcDbLayerTableRecord 对象的<p class="signature">void setIsOff(bool off);</p><p class="signatureInEnd">关闭图层</p>

luowy 发表于 2009-5-16 12:21:00

//-------------------------------------------------------------------------------//将关闭层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();
}

liub1979 发表于 2009-5-18 21:53:00

<p>再贴一个,希望对你有帮助</p><p>Adesk::Boolean SetIsOff (const char* lyrname,<br/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;bool off)<br/>{<br/>&nbsp;AcDbLayerTable *pLyrTable;<br/>&nbsp;AcDbLayerTableRecord *pLyrTblRecord;<br/>&nbsp;<br/>&nbsp;AcDbDatabase *pCurDb = NULL;<br/>&nbsp;pCurDb = acdbHostApplicationServices()-&gt;workingDatabase();<br/>&nbsp;<br/>&nbsp;// 获得当前图形的层表<br/>&nbsp;pCurDb-&gt;getLayerTable(pLyrTable, AcDb::kForRead);<br/>&nbsp;AcDbObjectId lyrId;<br/>&nbsp;// 是否已经包含指定的层表记录<br/>&nbsp;if (!pLyrTable-&gt;has(lyrname) &amp;&amp; !(lyrname == "*"))<br/>&nbsp;{<br/>&nbsp;&nbsp;pLyrTable-&gt;close();<br/>&nbsp;&nbsp;return Adesk::kFalse; <br/>&nbsp;}<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;pLyrTable-&gt;getAt(lyrname, lyrId);<br/>&nbsp;}<br/>&nbsp;AcDbLayerTableIterator *pItr; <br/>&nbsp;pLyrTable-&gt;newIterator(pItr); <br/>&nbsp;if (lyrname == "*")<br/>&nbsp;{<br/>&nbsp;&nbsp;for (pItr-&gt;start(); !pItr-&gt;done(); pItr-&gt;step()) <br/>&nbsp;&nbsp;{&nbsp;// 遍历器记录<br/>&nbsp;&nbsp;&nbsp;pItr-&gt;getRecord(pLyrTblRecord, AcDb::kForWrite);&nbsp;<br/>&nbsp;&nbsp;&nbsp;pLyrTblRecord-&gt;setIsOff(off);<br/>&nbsp;&nbsp;&nbsp;pLyrTblRecord-&gt;close();<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;else<br/>&nbsp;{<br/>&nbsp;&nbsp;for (pItr-&gt;start(); !pItr-&gt;done(); pItr-&gt;step()) <br/>&nbsp;&nbsp;{&nbsp;// 遍历器记录<br/>&nbsp;&nbsp;&nbsp;if(pItr-&gt;seek(lyrId) == Acad::eOk)<br/>&nbsp;&nbsp;&nbsp;{<br/>&nbsp;&nbsp;&nbsp;&nbsp;pItr-&gt;getRecord(pLyrTblRecord, AcDb::kForWrite);&nbsp;<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLyrTblRecord-&gt;setIsOff(off);<br/>&nbsp;&nbsp;&nbsp;&nbsp;pLyrTblRecord-&gt;close();<br/>&nbsp;&nbsp;&nbsp;&nbsp;break;<br/>&nbsp;&nbsp;&nbsp;}<br/>&nbsp;&nbsp;}<br/>&nbsp;}<br/>&nbsp;delete pItr;<br/>&nbsp;<br/>&nbsp;pLyrTable-&gt;close();<br/>&nbsp;return Adesk::kTrue;<br/>}</p>
页: [1]
查看完整版本: 關閉圖層問題