Acad::ErrorStatus TWArxLayerMan::Init() { AcDbDatabase* pDb = GetWorkingDB(); Acad::ErrorStatus es = Acad::eOk; AcDbLayerTable* pLayerTb = NULL; es = pDb->getLayerTable( pLayerTb,AcDb::kForRead ); if( pLayerTb == NULL ) return es; pLayerTb->close(); AcDbLayerTableIterator* pIte = NULL; es = pLayerTb->newIterator( pIte ); if( pIte == NULL ) return es; m_vLayers.clear(); for ( pIte->start(); !pIte->done(); pIte->step()) { AcDbObjectId Id; es = pIte->getRecordId( Id ); if( es != Acad::eOk ) continue; m_vLayers.push_back( Id ); } TWFreePtr( pIte ); return es; }
int ads_MyDialog() { // sample from brxtemplate //++-- See StdAfx for these types StringPairs LayerList; AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); pDb->layerTableId(); LayerTablePointer pLayerTable(pDb->layerTableId(),AcDb::kForRead); if(pLayerTable.openStatus() != eOk) { ads_retnil(); return( RSRSLT); } AcDbLayerTableIterator *pLayerTableIterator; pLayerTable->newIterator(pLayerTableIterator); //++-- iterate though and get our stuff for (pLayerTableIterator->start(); !pLayerTableIterator->done(); pLayerTableIterator->step()) { AcDbObjectId LayerId; TCHAR *LayerName; CString LayerColor; pLayerTableIterator->getRecordId(LayerId); LayerTableRecordPointer pLayerTableRecord(LayerId,AcDb::kForRead); pLayerTableRecord->getName(LayerName); AcCmColor clr = pLayerTableRecord->color(); LayerColor = clr.bookName(); LayerColor.Format(_T("Red = %03d Green = %03d Blue = %03d "), clr.red(), clr.green() , clr.blue()); LayerList.push_back(StringPair(String(LayerName), String(LayerColor))); } delete pLayerTableIterator; { // you should always call this before your diaog; CAcModuleResourceOverride resOverride; //show our dialog MyDialog dlg(LayerList,CWnd::FromHandle(adsw_acadMainWnd())); dlg.DoModal(); } ads_retnil(); return( RSRSLT); }
bool Additional_Class::LaylerFilter( AcDbObjectIdArray &EntityID, bool(*Filter)(AcDbEntity*, AcDbObjectId&) ) { // 遍历所有图层符合规则的实体返回ID列表 bool RunState = false; AcDbObjectIdArray LayerID_Array; vector<CString> LayerName_Array; AcDbObjectIdArray tempIDList; AcDbLayerTable *pLayerTbl; AcDbLayerTableRecord *pLayerTblRcd; acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite); AcDbLayerTableIterator *pltr; pLayerTbl->newIterator(pltr); // 图层遍历器 ACHAR *layerName; for (pltr->start(); !pltr->done(); pltr->step()) { pltr->getRecord(pLayerTblRcd,AcDb::kForRead); pLayerTblRcd->getName(layerName); // 得到图层名称 LayerName_Array.push_back(layerName); //pLayerTbl->getAt(layerName,layerId); // 得到图层ID //LayerID_Array.append(layerId); // 得到所有图层的ID列表 } pLayerTbl->close(); pLayerTblRcd->close(); // 对每层实体进行遍历 for (int i=0; i<LayerName_Array.size(); i++) { RunState = LaylerFilter(LayerName_Array.at(i), EntityID, Filter); } //for (pltr->start(); !pltr->done(); pltr->step()) //{ // // 遍历所有图层开始 // pltr->getRecord(pLayerTblRcd,AcDb::kForRead); // pLayerTblRcd->getName(layerName); // 得到图层名称 // pLayerTbl->getAt(layerName,layerId); // for (pltrX->start(); !pltrX->done(); pltrX->step()) // { // if(Acad::eOk ==pltrX->getEntity(pEnt, AcDb::kForRead, false)) // { // if (200>Check_Entity(pEnt)>=100) // { // temp_layerId = pEnt->layerId(); // if (temp_layerId == layerId) // { // entityID = pEnt->objectId(); // if (Filter(pEnt, entityID) == true) // { // EntityID.append(entityID); // } // } // } // } // } // // //RunState = LaylerFilter(layerName, tempIDList, Filter); // //if (RunState == true) // //{ // // for (int j = 0; j<tempIDList.length(); j++) // // { // // EntityID.append(tempIDList[j]); // // } // //} //} //pLayerTblRcd->close(); //pLayerTbl->close(); //pBlkTbl->close(); //pBlkTblRcd->close(); delete pltr; return false; }
void DelLayer() { ACHAR szNewName[256]; _tcscpy(szNewName, _T("NewLayer")); AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase(); if (pCurDb == NULL) { acutPrintf(_T("\nError:Current database is NULL!")); return; } bool bHas = false; bool bDeled = false; Acad::ErrorStatus es; AcDbObjectId layerId; AcDbLayerTable* pLayerTbl = NULL; es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForRead); if (es == Acad::eOk) { if (pLayerTbl->has(szNewName)) { AcDbLayerTableRecord* pLayerTblRcd = NULL; AcDbLayerTableIterator* pLTblIter = NULL; pLayerTbl->newIterator(pLTblIter); for (pLTblIter->start(); !pLTblIter->done(); pLTblIter->step()) { ACHAR* szLayerName = NULL; pLTblIter->getRecord(pLayerTblRcd, AcDb::kForWrite, true); if (pLayerTblRcd) { pLayerTblRcd->getName(szLayerName); if (_tcscmp(szNewName, szLayerName) == 0) { es = pLayerTblRcd->erase(true); if (es == Acad::eOk) { bDeled = true; } } if (szLayerName) { ads_free(szLayerName); } pLayerTblRcd->close(); } } if (pLTblIter) { delete pLTblIter; pLTblIter = NULL; } } pLayerTbl->close(); } if (bDeled) { acutPrintf(_T("\nErased the layer: \"%s\" successfully!"), szNewName); } else { acutPrintf(_T("\nFailed to erase the layer: \"%s\""), szNewName); } }