ObjectARX采用命名对象字典
为了使用方便,再此封装了,图形数据库字典项数据库//绑定命名字典值
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);
页:
[1]