最初由 ppengxm 发布
[B]在不关闭当前文档的前提下,如何做到删除当前数据库中所有层,使其恢复到只有一个基本的0层呢?
问题很急,望高手给小妹提供些建议。 [/B]
Look this.
- #include "dbobjptr.h"
- // Function name : HYT_ClearLayers
- // Description : 清除无关图层, 删除ModalSpace中不以"FC_"打头的层
- // Return type : void
- void HYT_ClearLayers()
- {
- #ifdef OARXWIZDEBUG
- acutPrintf ("\nOARXWIZDEBUG - HYT_ClearLayers() called.");
- #endif // OARXWIZDEBUG
- // TODO: Implement the command
- Acad::ErrorStatus es;
- AcDbDatabase* pCurDb = acdbHostApplicationServices()-> workingDatabase();
- AcDbLayerTablePointer spLayerTable(pCurDb,AcDb::kForWrite);
- es = spLayerTable.openStatus();
- if (es == Acad::eOk)
- {
- AcDbLayerTableIterator* pIterator;
- spLayerTable-> newIterator (pIterator);
-
- AcDbLayerTableRecord* pLayer;
- char* pLayerName=NULL;
-
- for (; !pIterator-> done(); pIterator-> step()) {
-
- pIterator-> getRecord (pLayer,AcDb::kForWrite) ;
-
- pLayer-> getName(pLayerName);
- if (acutWcMatch(pLayerName,"FC_*")!=RTNORM)
- {
- if (pLayer-> isLocked())
- pLayer-> setIsLocked(false);
- }
- pLayer-> close();
- acutDelString(pLayerName);
- }
- delete pIterator ;
- }
- else
- return;
- AcDbBlockTableRecordPointer spBlkRcd(ACDB_MODEL_SPACE, pCurDb, AcDb::kForRead);
- es = spBlkRcd.openStatus();
- if (es == Acad::eOk)
- {
- AcDbBlockTableRecordIterator *pIter;
- es = spBlkRcd-> newIterator(pIter);
- if (es == Acad::eOk)
- {
- AcDbEntity *pEnt;
- char *pLayerName = NULL;
- for (pIter-> start(); !pIter-> done(); pIter-> step())
- {
- es = pIter-> getEntity(pEnt,AcDb::kForRead);
- if (es == Acad::eOk)
- {
- pLayerName = pEnt-> layer();
-
- if (acutWcMatch(pLayerName,"FC_*")!=RTNORM)
- {
- es = pEnt-> upgradeOpen();
- if (es == Acad::eOk)
- pEnt-> erase();
- };
- acutDelString(pLayerName);
- pEnt-> close();
- }
- }
- delete pIter;
- }
- }
- else
- return;
-
- AcDbLayerTableIterator* pIterator;
- spLayerTable-> newIterator(pIterator);
-
- AcDbLayerTableRecord* pLayer;
- char* pLayerName=NULL;
-
- for (; !pIterator-> done(); pIterator-> step()) {
-
- pIterator-> getRecord (pLayer,AcDb::kForWrite) ;
-
- pLayer-> getName(pLayerName);
- if (acutWcMatch(pLayerName,"0,FC_*")!=RTNORM)
- {
- pLayer-> erase();
- }
- pLayer-> close();
- acutDelString(pLayerName);
- }
-
- delete pIterator;
- }
|