void Additional_Class::SetLayerIsOff( CString strLayerName) { AcDbLayerTable *pLayTbl = NULL; acdbCurDwg()->getLayerTable(pLayTbl, AcDb::kForWrite); if(!pLayTbl->has(strLayerName)) { pLayTbl->close(); //该图层不存在 return; } AcDbLayerTableRecord *pLayTblRec = NULL; AcDbObjectId objId; pLayTbl->getAt(strLayerName, pLayTblRec, AcDb::kForWrite); pLayTbl->close(); //pLayTblRec->isInUse(); if (pLayTblRec==NULL) { return; } bool tempBool = pLayTblRec->isOff(); if (tempBool == false) { pLayTblRec->setIsOff(true); } else { pLayTblRec->setIsOff(false); } pLayTblRec->close(); return; }
void ModifyLayerProp() { CString strLayerName(_T("NewLayer")); AcDbLayerTable* pLayerTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl, AcDb::kForRead); if (!pLayerTbl->has(strLayerName)) { pLayerTbl->close(); acutPrintf(_T("\nNo existed layer:\"%s\"."), strLayerName); return; } Acad::ErrorStatus es; AcDbLayerTableRecord* pLayerTblRcd = NULL; pLayerTbl->getAt(strLayerName, pLayerTblRcd, AcDb::kForWrite); AcCmColor oldColor = pLayerTblRcd->color(); int nCurColor = oldColor.colorIndex(); int nNewColor = oldColor.colorIndex(); if (acedSetColorDialog(nNewColor, Adesk::kFalse, nCurColor)) { AcCmColor color; color.setColorIndex(nNewColor); pLayerTblRcd->setColor(color); acutPrintf(_T("\nThe color of layer:\"%s\" has modified!"), strLayerName); } pLayerTblRcd->close(); pLayerTbl->close(); }
//把一层设置为OFF or ON void CArxHelper::SetOneLayer(const TCHAR *name,int flag,bool YN) //flag 1:isoff 2:isfrozen 3:islocked { AcDbLayerTable *pLayerTable; acdbCurDwg()->getLayerTable(pLayerTable,AcDb::kForRead); if(!pLayerTable->has(name)) { pLayerTable->close(); return; } AcDbObjectId id; pLayerTable->getAt(name,id); AcDbLayerTableRecord *pLayerTableRecord; acdbOpenObject(pLayerTableRecord,id,AcDb::kForWrite); switch(flag) { case 1: pLayerTableRecord->setIsOff(YN); break; case 2: pLayerTableRecord->setIsFrozen(YN); break; case 3: pLayerTableRecord->setIsLocked(YN); break; } pLayerTableRecord->close(); pLayerTable->close(); }
static void CheakLayerExit(CString layerName,int colorIndx, AcDb::LineWeight lineWeigt) { //int colorIndx = 7; //默认的颜色为白色 //AcDb::LineWeight lineWeigt = AcDb::kLnWt000; //lineWeigt = AcDb::kLnWt030; AcDbLayerTable* pLayerTbl = NULL; // 获取当前的数据库 AcDbDatabase*pDB=acdbHostApplicationServices()->workingDatabase(); // 因为要创建新的图层,所以先要以写的方式获取图层表 pDB->getSymbolTable(pLayerTbl,AcDb::kForWrite); // 检查图层是否存在 if (!pLayerTbl->has(layerName)) { // 初始化一个新的对象,并且设置它的属性 AcDbLayerTableRecord *pLayerTblRcd = new AcDbLayerTableRecord; pLayerTblRcd->setName(layerName); pLayerTblRcd->setIsFrozen(0); // 图层设置为THAWED(解冻的) pLayerTblRcd->setIsOff(0); // 图层设置为ON(开着的) pLayerTblRcd->setIsLocked(0); // 图层 un-locked(解锁的) AcCmColor color; color.setColorIndex(colorIndx); // 图层的颜色设置 pLayerTblRcd->setColor(color); pLayerTblRcd->setLineWeight(lineWeigt); // 增加一个新的图层到容器(表)中 pLayerTbl->add(pLayerTblRcd); // 把新建的图层关闭(不要删除它) pLayerTblRcd->close(); // 关闭容器(表) pLayerTbl->close(); } else { // 如果这个图层已经存在,仅仅需要关闭表继续就是 AcDbLayerTableRecord *pLayerTblRcd; pLayerTbl->getAt(layerName, pLayerTblRcd, AcDb::kForWrite); AcCmColor color; color.setColorIndex(colorIndx); // 图层的颜色设置 pLayerTblRcd->setColor(color); pLayerTblRcd->setLineWeight(lineWeigt); pLayerTblRcd->close(); pLayerTbl->close(); //acutPrintf(_T("\nMYLAYER already exists")); } }
Acad::ErrorStatus TWArxLayer::Create( OUT AcDbObjectId& IdLayer ) const { if( m_strName.IsEmpty() ) return Acad::eInvalidInput; AcDbDatabase* pDb = GetWorkingDB(); Acad::ErrorStatus es = Acad::eKeyNotFound; AcDbLayerTable* pLayerTb = NULL; es = pDb->getLayerTable( pLayerTb,AcDb::kForRead ); if( pLayerTb == NULL ) return es; es = pLayerTb->getAt( m_strName, IdLayer ); if( es == Acad::eOk ) { pLayerTb->close(); return es; } es = pLayerTb->upgradeOpen(); AcDbLayerTableRecord* pLtr = new AcDbLayerTableRecord; pLtr->setName( m_strName ); pLtr->setIsFrozen( m_bIsFrozen ); pLtr->setIsLocked( m_bIsLocked ); pLtr->setIsOff( m_bIsOff ); es = pLayerTb->add( IdLayer, pLtr ); pLayerTb->close(); if( es == Acad::eOk ) { pLtr->close(); return es; } TWFreePtr( pLtr ); return es; }
void CLayerTreeDlg::ShowLayer(HTREEITEM hItem, BOOL bShow) { CString sLayerName = m_tree.GetItemText(hItem); HTREEITEM hChild = m_tree.GetNextItem(hItem,TVGN_CHILD); // 只有树叶才有对应的图层 if (hChild == NULL) { ShowLayer(sLayerName, bShow); //如果是面层,还要把它的填充图层打开 CString sHatchLayer; sHatchLayer.Format("%s_填充",sLayerName); bool hasHatch = false; acDocManager->lockDocument(acDocManager->curDocument()); AcDbLayerTable * pLayerTbl = NULL; Acad::ErrorStatus es = acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead); if (pLayerTbl->has(sHatchLayer)) { AcDbLayerTableRecord * pLayerTbRcd = NULL; es = pLayerTbl->getAt(sHatchLayer,pLayerTbRcd,AcDb::kForWrite); pLayerTbRcd->setIsOff(bShow == 0); pLayerTbRcd->close(); hasHatch = true; } pLayerTbl->close(); acDocManager->unlockDocument(acDocManager->curDocument()); } while(hChild != NULL) { ShowLayer(hChild, bShow); hChild = m_tree.GetNextItem(hChild,TVGN_NEXT); } }
bool Additional_Class::Get_LayerLW( CString LayerName, double &Length, double &Width ) { AcDbLayerTable *pLayerTbl = NULL; acdbHostApplicationServices()->workingDatabase()->getSymbolTable(pLayerTbl,AcDb::kForRead); if (!pLayerTbl->has(LayerName)) { //acutPrintf("\n木有%s层!", LayerName); //SetError("THERE ISN`T"+LayerName+"LATYER!", "Get_LayerLW"); pLayerTbl->close(); return false; } AcDbObjectId layerId; pLayerTbl->getAt(LayerName, layerId); pLayerTbl->close(); AcDbBlockTable *pBlkTbl = NULL; ////获得当前数据库块表 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite); ////获得模型空间块表记录 AcDbBlockTableRecord *pBlkTblRcd = NULL; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForRead); pBlkTbl->close(); ////创建块表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlkTblRcd->newIterator(pltr); AcDbEntity *pEnt; //AcDbEntityPointer pEnt_Ptr; ////AcDbObjectPointer<AcDbPolyline> pPolyLine_Ptr; AcDbPolyline *pPolyLine = NULL; AcDbObjectIdArray PolyLineID_List; for (pltr->start(); !pltr->done(); pltr->step()) { pltr->getEntity(pEnt, AcDb::kForRead); // //pEnt_Ptr.acquire(pEnt); if (pEnt->layerId()==layerId) { if (pEnt->isKindOf(AcDbPolyline::desc())) { pPolyLine = AcDbPolyline::cast(pEnt); if (pPolyLine != NULL) { if (PolyLineIfRectangle(pPolyLine)==true) { PolyLineID_List.append(pPolyLine->objectId()); } } } } } if (PolyLineID_List.length() >1) { acutPrintf(_T("Bom Error 1002\n"));// 有很多矩形 delete pltr; pEnt->close(); pPolyLine->close(); pBlkTblRcd->close(); return false; } ////pPolyLine.open(PolyLineID_List[0], AcDb::kForRead); acdbOpenAcDbEntity(pEnt,PolyLineID_List[0], AcDb::kForRead); //error! pPolyLine = AcDbPolyline::cast(pEnt); Get_RectangleLW(pPolyLine, Length, Width); pBlkTblRcd->close(); pPolyLine->close(); pEnt->close(); delete pltr; return true; }
bool Additional_Class::LaylerFilter( CString LaylerName, AcDbObjectIdArray &EntityID_Array, bool(*Filter)(AcDbEntity*, AcDbObjectId&) ) { AcDbLayerTable *pLayerTbl; acdbHostApplicationServices()->workingDatabase()->getLayerTable(pLayerTbl,AcDb::kForWrite); if (false == (pLayerTbl->has(LaylerName))) { //acutPrintf("\n木有%s层!", LaylerName); //SetError("THERE ISTN`T"+LaylerName+"LAYER!", "LaylerFilter"); pLayerTbl->close(); return false; } AcDbObjectId layerId; pLayerTbl->getAt(LaylerName,layerId); AcDbBlockTable *pBlkTbl; //获得当前数据库块表 acdbHostApplicationServices()->workingDatabase()->getBlockTable(pBlkTbl,AcDb::kForWrite); //获得模型空间块表记录 AcDbBlockTableRecord *pBlkTblRcd; pBlkTbl->getAt(ACDB_MODEL_SPACE, pBlkTblRcd, AcDb::kForWrite); //创建块表记录遍历器 AcDbBlockTableRecordIterator *pltr; pBlkTblRcd->newIterator(pltr); AcDbEntity *pEnt; AcDbObjectId temp_layerId; AcDbObjectId entityID; //pBlkTblRcd->close(); //pBlkTbl->close(); //pLayerTbl->close(); for (pltr->start(); !pltr->done(); pltr->step()) { if(Acad::eOk ==pltr->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_Array.append(entityID); } } //} pEnt->close(); } } int Len = EntityID_Array.length(); if (Len == 0) { pBlkTbl->close(); pLayerTbl->close(); pBlkTblRcd->close(); return false; } pBlkTbl->close(); pLayerTbl->close(); pBlkTblRcd->close(); return true; }
void ModifyEntityLayer() { int nRet = 0; ads_name entName; ads_point ptPick; nRet = acedEntSel(_T("\nSelect an entity to change it's layer:"), entName, ptPick); if (nRet != RTNORM) { acutPrintf(_T("\nFailed to select!")); return; } Acad::ErrorStatus es; AcDbObjectId objId; AcDbEntity* pEnt = NULL; acdbGetObjectId(objId, entName); es = acdbOpenAcDbEntity(pEnt, objId, AcDb::kForWrite); if (es != Acad::eOk) { acutPrintf(_T("\nFailed to open entity!")); return; } ACHAR szNewName[255]; _tcscpy(szNewName, _T("NewLayer")); bool bHasDone = false; AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase(); if (pCurDb == NULL) { acutPrintf(_T("\nError:Current database is NULL!")); return; } AcDbObjectId layerId; AcDbLayerTable* pLayerTbl = NULL; es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForRead); if (es == Acad::eOk) { if (pLayerTbl->has(szNewName)) { es = pLayerTbl->getAt(szNewName, layerId); if (es == Acad::eOk) { es = pEnt->setLayer(layerId); if (es == Acad::eOk) { bHasDone = true; } } } pLayerTbl->close(); } pEnt->close(); if (bHasDone) { acutPrintf(_T("\nThe layer of entity has modified to layer:\"%s\""), szNewName); } else { acutPrintf(_T("\nFailed to modify the layer of entity to layer:\"%s\""), szNewName); } }