爲了使用方便,再此封裝了,圖形數據庫字典項數據庫
//綁定命名字典值 bool SetDictdata(const CString& strDictName,const CString strRecord,CString& strDictVal); //獲取命名字典的值 bool GetDictdata(const CString& strDictName,const CString strRecord, CString& strDictVal);
bool CQKQuery::SetDictdata( const CString& strDictName,const CString strRecord,CString& strDictVal ) { // 得到有名對象字典,向其中添加指定的字典項 AcDbDictionary *pNameObjDict = NULL; Acad::ErrorStatus es = m_pDb->getNamedObjectsDictionary(pNameObjDict,AcDb::kForWrite); if (Acad::eOk != es || NULL == pNameObjDict) return false; // 檢查所要添加的字典項是否已經存在 AcDbDictionary *pDict = NULL; es = pNameObjDict->getAt(strDictName, (AcDbObject*&)pDict,AcDb::kForWrite); if (es == Acad::eKeyNotFound || NULL == pDict)//沒有字典項,新建一個 { pDict = new AcDbDictionary; AcDbObjectId dictObjId; es = pNameObjDict->setAt(strDictName, pDict, dictObjId); if (Acad::eOk != es) { delete pDict; pDict = NULL; pNameObjDict->close(); return false; } AcDbXrecord *pXrec = new AcDbXrecord; // 設置擴展記錄的內容 struct resbuf *pRb = NULL; pRb = acutBuildList(AcDb::kDxfText, strDictVal,RTNONE); if (NULL == pRb) { delete pXrec; pXrec = NULL; pDict->close(); pNameObjDict->close(); return false; } pXrec->setFromRbChain(*pRb); acutRelRb(pRb); AcDbObjectId xrecObjId; es = pDict->setAt(strRecord, pXrec, xrecObjId); if (Acad::eOk != es) { delete pXrec; pXrec = NULL; pDict->close(); pNameObjDict->close(); return false; } pXrec->close(); pDict->close(); pNameObjDict->close(); } else//已經存在字典項 { //得到擴展數據 AcDbXrecord* pXrec = NULL; es = pDict->getAt(strRecord, (AcDbObject*&)pXrec, AcDb::kForWrite); if (es == Acad::eKeyNotFound || NULL == pXrec)//沒有擴展數據 { AcDbXrecord *pXrec = new AcDbXrecord; // 設置擴展記錄的內容 struct resbuf *pRb = NULL; pRb = acutBuildList(AcDb::kDxfText, strDictVal,RTNONE); if (NULL == pRb) { delete pXrec; pXrec = NULL; pDict->close(); pNameObjDict->close(); return false; } pXrec->setFromRbChain(*pRb); acutRelRb(pRb); AcDbObjectId xrecObjId; es = pDict->setAt(strRecord, pXrec, xrecObjId); if (Acad::eOk != es) { delete pXrec; pXrec = NULL; pDict->close(); pNameObjDict->close(); return false; } pXrec->close(); pDict->close(); pNameObjDict->close(); } else//有擴展數據 { // 設置擴展記錄的內容 struct resbuf *pRb = NULL; pRb = acutBuildList(AcDb::kDxfText, strDictVal,RTNONE); if (NULL == pRb) { pXrec->close(); pDict->close(); pNameObjDict->close(); return false; } pXrec->setFromRbChain(*pRb); acutRelRb(pRb); pXrec->close(); pDict->close(); pNameObjDict->close(); } } return true; } bool CQKQuery::GetDictdata( const CString& strDictName,const CString strRecord, CString& strDictVal ) { // 得到有名對象字典,向其中添加指定的字典項 AcDbDictionary *pNameObjDict = NULL; AcDbDictionary *pDict = NULL; Acad::ErrorStatus es = m_pDb->getNamedObjectsDictionary(pNameObjDict,AcDb::kForRead); if (es != Acad::eOk || NULL == pNameObjDict) return false; // 檢查所要添加的字典項是否已經存在 AcDbObjectId dictObjId; es = pNameObjDict->getAt(strDictName, (AcDbObject*&)pDict, AcDb::kForRead); if (es == Acad::eKeyNotFound || NULL == pDict) { pNameObjDict->close(); return false; } // 得到指定的對象字典 AcDbXrecord *pXrec = NULL; es = pDict->getAt(strRecord, (AcDbObject*&)pXrec, AcDb::kForRead); if (es != Acad::eOk || NULL == pXrec) { pDict->close(); pNameObjDict->close(); return false; } // 得到擴展記錄的數據鏈表並關閉擴展數據對象 struct resbuf *pRb = NULL; es = pXrec->rbChain(&pRb); if (es != Acad::eOk || NULL == pRb) { pXrec->close(); pDict->close(); pNameObjDict->close(); return false; } strDictVal = pRb->resval.rstring; acutRelRb(pRb); pXrec->close(); pDict->close(); pNameObjDict->close(); return true; }
具體用法:ui
SetDictdata(_T("FLAG"),_T("XRecord"),strId); GetDictdata(_T("FLAG"),_T("XRecord"),strId);