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 getAllSymbolRecordsIds(AcRxClass* pTableClass, AcDbObjectIdArray & idaAll) { CLogger::Print(_T("*Call: getAllSymbolRecordsIds()")); Acad::ErrorStatus es; idaAll.setLogicalLength(0); AcDbDatabase* pDb = acdbHostApplicationServices()->workingDatabase(); AcDbSymbolTable* pSymbolTable = NULL; if (AcRx::kEqual == pTableClass->comparedTo(AcDbBlockTable::desc())) { CLogger::Print(_T("> This is BlockTable!")); es = pDb->getBlockTable(pSymbolTable, AcDb::kForRead); } else if (AcRx::kEqual == pTableClass->comparedTo(AcDbLayerTable::desc())) { CLogger::Print(_T("> This is LayerTable!")); es = pDb->getLayerTable(pSymbolTable, AcDb::kForRead); } else if (AcRx::kEqual == pTableClass->comparedTo(AcDbLinetypeTable::desc())) { CLogger::Print(_T("> This is LinetypeTable!")); es = pDb->getLinetypeTable(pSymbolTable, AcDb::kForRead); } else if (AcRx::kEqual == pTableClass->comparedTo(AcDbTextStyleTable::desc())) { CLogger::Print(_T("> This is TextStyleTable!")); es = pDb->getTextStyleTable(pSymbolTable, AcDb::kForRead); } else { CLogger::Print(_T("*Exit: getAllSymbolRecordsIds() - This kind of SymbolTable is not supported!")); return -1; } if (Acad::eOk != es) { CLogger::Print(_T("*Exit: getAllSymbolRecordsIds() - Fail to get SymbolTable!")); return -1; } //------------ // Get the SymbolTable's iterator. AcDbSymbolTableIterator* pSymbolTableIter = NULL; es = pSymbolTable->newIterator(pSymbolTableIter); pSymbolTable->close(); if (Acad::eOk != es) { CLogger::Print(_T("*Exit: getAllSymbolRecordsIds() - Fail to get the SymbolTable's iterator!")); return -1; } //------------ // Steps through the SymbolTable's records. // Then get the SymbolTableRecord's ObjectID. for (; !pSymbolTableIter->done(); pSymbolTableIter->step()) { AcDbObjectId idObj = AcDbObjectId::kNull; if (Acad::eOk == pSymbolTableIter->getRecordId(idObj)) idaAll.append(idObj); } delete pSymbolTableIter; CLogger::Print(_T("*Exit: getAllSymbolRecordsIds() - Count: %02d"), idaAll.length()); return idaAll.length(); }
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 CMyDlg::OnCreateLine() { // TODO: Add your control notification handler code here acDocManager->lockDocument(curDoc()); int i; int m, n; char *buf = (char*)malloc(20); AcDbObjectId LineId; AcDbLine *pLine = NULL; //块表 AcDbBlockTable *pTb = NULL; //块表记录 AcDbBlockTableRecord *pTbr = NULL; //层表 AcDbLayerTable *pLyr = NULL; //层表记录 AcDbLayerTableRecord* pLyrr = NULL; //图形数据库 AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase(); Acad::ErrorStatus es; CListCtrl *pListCtr = (CListCtrl *)GetDlgItem( IDC_LIST1 ); //设置随机数种子 srand(time(NULL)); //更新数据 UpdateData(TRUE); m_VecSize += m_Edit5; m_xVec.resize(m_VecSize); m_yVec.resize(m_VecSize); //acutPrintf("%d\n", m_Edit1); es = pDb->getLayerTable(pLyr, AcDb::kForWrite); //以写的方式打开层表 es = pDb->getBlockTable(pTb, AcDb::kForRead); //以读的方式打开块表 es = pTb->getAt(ACDB_MODEL_SPACE, pTbr, AcDb::kForWrite);//以写的方式打开块表记录 //创建图层GalLineTest if (!pLyr->has("GalLineTest")) { pLyrr = new AcDbLayerTableRecord; //创建层记录 pLyrr->setName("GalLineTest"); //设置名字 //pLyrr->setColor(color); //设置颜色 //pLyrr->setLineWeight(lnWt); //设置线宽 if (Acad::eOk != pLyr->add(pLyrr)) //添加该层记录到层表 { //添加失败 delete pLyrr; //释放内存 pLyr->close(); //关闭层表 } //关闭层表记录 pLyrr->close(); } //关闭层表 pLyr->close(); //生成点坐标 for (i = 0; i < m_Edit5; ++i) { if ((m_Edit2 != 0) && (m_Edit4 != 0)) { m_xVec[i] = rand() % m_Edit2 + m_Edit1; m_yVec[i] = rand() % m_Edit4 + m_Edit3; } else { m_xVec[i] = 0; m_yVec[i] = 0; } } //遍历点坐标 for (m = 0; m < m_Edit5; ++m) { for (n = (m+1); n < m_Edit5; ++n) { if ((m_xVec[m] != m_xVec[n]) && (m_yVec[m] != m_yVec[n])) { AcGePoint3d ptStart(m_xVec[m], m_yVec[m], 0); AcGePoint3d ptEnd(m_xVec[n], m_yVec[n], 0); pLine = new AcDbLine(ptStart, ptEnd); //pLine->setColor(); pLine->setLayer("GalLineTest"); //创建线段 es = pTbr->appendAcDbEntity(LineId, pLine); if (Acad::eOk == es) { ++m_lLineCnt; } //acutPrintf("%d\n", LineId); sprintf(buf, "%d", LineId); m_ListCtr.InsertItem(m_Row, buf); buf = itoa(pLine->colorIndex(), buf, 10); m_ListCtr.SetItemText(m_Row, 1, buf); buf = itoa(LineLength(m_xVec[m], m_yVec[m], m_xVec[n], m_yVec[n]), buf, 10); m_ListCtr.SetItemText(m_Row, 2, buf); ++m_Row; pLine->close(); //关闭实体 } } } pTbr->close(); //关闭块表记录 pTb->close(); //关闭块表 acDocManager->unlockDocument(curDoc()); free(buf); }
void CreateLayer() { Acad::ErrorStatus es; ACHAR szNewName[255]; _tcscpy(szNewName, _T("NewLayer")); AcDbDatabase* pCurDb = acdbHostApplicationServices()->workingDatabase(); if (pCurDb == NULL) { acutPrintf(_T("\nError:Current database is NULL!")); return; } AcDbLayerTableRecord* pNewLayer = new AcDbLayerTableRecord; es = pNewLayer->setName(szNewName); if (es != Acad::eOk) { acutPrintf(_T("\nFailed setName of the layer!")); delete pNewLayer; return; } AcCmColor cmColor; cmColor.setColorIndex(1); pNewLayer->setColor(cmColor); pNewLayer->setIsFrozen(false); pNewLayer->setIsOff(false); pNewLayer->setVPDFLT(false); pNewLayer->setIsLocked(false); bool bStat = false; AcDbLayerTable* pLayerTbl = NULL; es = pCurDb->getLayerTable(pLayerTbl, AcDb::kForWrite); if (es == Acad::eOk) { if (pLayerTbl->has(szNewName)) { acutPrintf(_T("\nThe Layer \"%s\" has existed!"), szNewName); delete pNewLayer; } else { es = pLayerTbl->add(pNewLayer); if (es == Acad::eOk) { bStat = true; pNewLayer->close(); } else { acutPrintf(_T("\nFailed to add a new layer in LayerTable!")); delete pNewLayer; } } pLayerTbl->close(); } if (bStat) { acutPrintf(_T("\nCreated the new layer: \"%s\" successfully!"), szNewName); } else { acutPrintf(_T("\nFailed to create the layer: \"%s\""), szNewName); } }
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); } }
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); } }
// This command demonstrates the use of kCleanup / kReuse flags void AddEntityToLayer (AsdkHlrCollector &collector, ACHAR *layerName) { //----- Check layer if ( layerName != NULL && *layerName != ACRX_T('\0') ) { AcDbDatabase *pDb =acdbHostApplicationServices ()->workingDatabase () ; AcDbLayerTable *pLayerTable ; pDb->getLayerTable (pLayerTable, AcDb::kForRead) ; if ( !pLayerTable->has (layerName) ) { AcDbLayerTableRecord *pLayerRecord =new AcDbLayerTableRecord ; pLayerRecord->setName (layerName) ; pLayerTable->upgradeOpen () ; pLayerTable->add (pLayerRecord) ; pLayerTable->downgradeOpen () ; pLayerRecord->close () ; pLayerTable->close () ; applyCurDwgLayerTableChanges () ; } else { pLayerTable->close () ; } } else { layerName =NULL ; } //----- Assign color to the resulting entities //----- red for visible edges //----- blue for non-visible edges //----- yellow for internal edges int n =collector.mOutputData.logicalLength () ; for ( int i =0 ; i < n ; i++ ) { AsdkHlrData *p =collector.mOutputData [i] ; AcDbEntity *pEnt =p->getResultEntity () ; AsdkHlrData::Visibility vis =p->getVisibility () ; if ( vis == AsdkHlrData::kVisible ) { pEnt->setColorIndex (1) ; //----- Read } else if ( vis == AsdkHlrData::kInternallyHidden ) { if ( p->getHlrVisibility () == AsdkHlrData::kVisible ) pEnt->setColorIndex (2) ; //----- Yellow else pEnt->setColorIndex (3) ; //----- Green } else { pEnt->setColorIndex (5) ; //----- Blue } if ( layerName != NULL ) pEnt->setLayer (layerName) ; AcDbObjectId id ; if ( postToDatabase (NULL, pEnt, id) != Acad::eOk ) { acutPrintf (_T("Failed to add entity to current space.\n")) ; break ; } //----- Entity originator path for block reference entities AcDbObjectIdArray ids =p->getObjectIds () ; if ( ids.logicalLength () > 0 ) { acutPrintf (ACRX_T("\n%ld, "), pEnt->objectId ().asOldId ()) ; for ( int j =0 ; j < ids.logicalLength () ; j++ ) { acutPrintf (ACRX_T("%ld, "), ids.at (j).asOldId ()) ; } } pEnt->close () ; } }