bool Additional_Class::FindLayer( CString LaylerName ) { int n = 0;//判断是否找到图层 ////////////////////////////////////////////////////////////////////////// AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForWrite); // 建立图层遍历器 AcDbLayerTableIterator *pLayerIterator; pLayerTbl->newIterator(pLayerIterator); // AcDbLayerTableRecord *pLayerTableRcd; ACHAR *pLtName; ACHAR *pLtNameTT; CString pLtNameStr; for (; !pLayerIterator->done(); pLayerIterator->step()) { pLayerIterator->getRecord(pLayerTableRcd, AcDb::kForWrite); pLayerTableRcd->getName(pLtName); pLayerTableRcd->close(); pLtNameStr = pLtName; if (pLtNameStr == LaylerName) { return true; } else { free(pLtName); } } return false; }
AcDbObjectId CArxHelper::SetLayer(TCHAR* layerName) { AcDbObjectId layerId = NULL; AcDbLayerTable *pLayerTbl; acdbCurDwg()->getLayerTable(pLayerTbl,AcDb::kForWrite); AcDbLayerTableIterator *pItr; pLayerTbl->newIterator(pItr); for(;!pItr->done();pItr->step()) { AcDbLayerTableRecord *pLayer; pItr->getRecord(pLayer,AcDb::kForRead); TCHAR *str=NULL; pLayer->getName(str); if(_tcscmp(layerName,str)==0) layerId=pLayer->id(); if(str!=NULL) delete []str; pLayer->close(); if(layerId!=NULL) break; } delete pItr; pItr = NULL; if(layerId==NULL) { AcDbLayerTableRecord *pLayerTblRcd=new AcDbLayerTableRecord(); Acad::ErrorStatus es = pLayerTblRcd->setName(layerName); if (es != Acad::eOk) pLayerTblRcd->setName(_T("0")); pLayerTbl->add(layerId,pLayerTblRcd); pLayerTblRcd->close(); } pLayerTbl->close(); acdbCurDwg() ->setClayer(layerId); return layerId; }
void AecUiPrEntitySet::getLockedLayers() { m_lockedLayerCache.setLogicalLength(0); m_lockedLayerNames.RemoveAll(); if (m_filterLockedLayers == Adesk::kFalse) return; AcDbLayerTableRecord* layer; const TCHAR* tmpName; AcDbLayerTable* layTbl; Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()->getSymbolTable(layTbl, AcDb::kForRead); if (es == Acad::eOk) { AcDbLayerTableIterator* tblIter; if (layTbl->newIterator(tblIter) == Acad::eOk) { for (; !tblIter->done(); tblIter->step()) { es = tblIter->getRecord(layer, AcDb::kForRead); if (es == Acad::eOk) { if (layer->isLocked()) { m_lockedLayerCache.append(layer->objectId()); es = layer->getName(tmpName); if (es == Acad::eOk) { m_lockedLayerNames.Add(tmpName); } else { AEC_ASSERT(0); m_lockedLayerNames.Add(_DNT(_T(""))); // have to keep balanced } } layer->close(); } } delete tblIter; } else { AEC_ASSERT(0); } layTbl->close(); } }
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 Additional_Class::SetCurLayler( CString LaylerName ) { AcDbDatabase *pCurDb = NULL; pCurDb = acdbHostApplicationServices()->workingDatabase(); /*pCurDb->setClayer()*/ int n = 0;//判断是否找到图层 ////////////////////////////////////////////////////////////////////////// AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase() ->getSymbolTable(pLayerTbl, AcDb::kForWrite); // 建立图层遍历器 AcDbLayerTableIterator *pLayerIterator; pLayerTbl->newIterator(pLayerIterator); // AcDbLayerTableRecord *pLayerTableRcd; ACHAR *pLtName; ACHAR *pLtNameTT; CString pLtNameStr; for (; !pLayerIterator->done(); pLayerIterator->step()) { pLayerIterator->getRecord(pLayerTableRcd, AcDb::kForWrite); pLayerTableRcd->getName(pLtName); pLayerTableRcd->close(); pLtNameStr = pLtName; if (pLtNameStr == LaylerName) { pCurDb->setClayer(pLayerTableRcd->id()); free(pLtName); n = 1;//如果图层找到,则将n赋值为1 delete pLayerIterator; pLayerTbl->close(); return; } else { free(pLtName); } } if (n == 0) { // 新建图层 AcDbLayerTableRecord *pLayerTableRecordTT = new AcDbLayerTableRecord; pLayerTableRecordTT->setName(LaylerName); AcDbObjectId pLayerId; pLayerTbl->add(pLayerId, pLayerTableRecordTT); pLayerTableRecordTT->getName(pLtNameTT); pLayerTableRecordTT->close(); //struct resbuf pResult; //::acedGetVar(_T("CLAYER"),&pResult);//取得当前图层 //char *p = (LPSTR)(LPCTSTR)LaylerName; //pResult.resval.rstring = pLtNameTT; //int s=acedSetVar(_T("CLAYER"), &pResult);//将输入的图层设为当前层 //相当于命令 CLAYER LAYERNAME //acutPrintf(_T("\nLinetype name is: %s"), pResult.resval.rstring); //acutPrintf(_T("\nLinetype name is: %d"), s); n = 1;//如果图层找到,则将n赋值为1 delete pLayerIterator; pLayerTbl->close(); struct resbuf pResults; ::acedGetVar(_T("CLAYER"),&pResults);//取得当前图层 //pLtNameTT = "0"; pResults.resval.rstring = pLtNameTT; ::acedSetVar(_T("CLAYER"), &pResults);//将输入的图层设为当前层 free(pLtNameTT); } // acutPrintf(_T("\nLinetype name")); // acutPrintf(_T("\nLinetype name is: %s"), pResult.resval.rstring); }
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); } }