www.mxdraw.com
内容索引主面
前一个向上下一个
McDbXrecord 类

扩展记录类型,实体可以设置它的扩展记录,用于存放更多的信息

C++
class McDbXrecord : public McDbObject;

McDbXrecord.h

例如:写实体的扩展记录代码如下

    void CTestCommands::Writexrecorddata()
    {
        ads_name entName;
        ads_point pt;
        if(acedEntSel(_T("选择写扩展记录数据的实体:"),entName,pt) != RTNORM)
        {
            return;
        }
        AcDbObjectId objId;
        if(acdbGetObjectId(objId,entName) != Acad::eOk)
            return;


        struct resbuf* pData = acutBuildList(RTSTR,_T("Test"),RTLONG,4555,0);

        WriteXRecord(pData,objId,_T("TestRecordName"));

        acutRelRb(pData);
    }
    bool CTestCommands::WriteXRecord(struct resbuf* pRbValue,const AcDbObjectId &id,LPCTSTR pszxRecordName)
    {
        AcDbObjectPointer<AcDbObject> pObj(id,AcDb::kForWrite);
        if(pObj.openStatus() != Acad::eOk)
        {
            return false;
        }

        if(pszxRecordName == NULL || pRbValue == NULL)
        {
            acutPrintf(_T("n参数为空!"));
            return false;
        }

        //得到实体的字典ID
        AcDbObjectId extDictId = pObj->extensionDictionary();
        if (extDictId == AcDbObjectId::kNull) 
        {
            Acad::ErrorStatus es = pObj->createExtensionDictionary();
            if (es != Acad::eOk) 
            {
                acutPrintf(_T("n创建扩展字典错误:%d!"),es);
                return false;
            }
            if ((extDictId = pObj->extensionDictionary()) == AcDbObjectId::kNull) 
            {
                acutPrintf(_T("n错误: 不能创建扩展字典!"));
                return false;
            }
        }

        //创建新的扩展记录
        AcDbObjectPointer<McDbDictionary> pDict(extDictId,AcDb::kForRead);
        if(pDict.openStatus() != Acad::eOk)
        {
            acutPrintf(_T("n读方式打开字典失败!"));
            return false;
        }
        AcDbObjectId xRecId;
        if(pDict->getAt(pszxRecordName,xRecId) != Acad::eOk)
        {
            AcDbXrecord* pXrec = new AcDbXrecord;
            pDict->upgradeOpen();
            if(pDict->setAt(pszxRecordName,pXrec,xRecId) != Acad::eOk)
            {
                acutPrintf(_T("n创建新的扩展记录数据失败!"));
                return false;
            }
            pXrec->close();
        }

        //写数据
        AcDbObjectPointer<AcDbXrecord> pXrcord(xRecId,AcDb::kForWrite);
        if(pXrcord.openStatus() != Acad::eOk)
        {
            acutPrintf(_T("n写方式打开扩展记录失败"));
            return false;
        }
        else
        {
            if(pXrcord->setFromRbChain(*pRbValue) != Acad::eOk)
            {
                acutPrintf(_T("nsetFromRbChain() 失败!"));
                return false;
            }
        }

        return true;
    }

例如:读实体的扩展记录代码如下

    void CTestCommands::Readxrecorddata()
    {
        ads_name entName;
        ads_point pt;
        if(acedEntSel(_T("选择实体:"),entName,pt) != RTNORM)
        {
            return;
        }
        AcDbObjectId objId;
        if(acdbGetObjectId(objId,entName) != Acad::eOk)
            return;

        AcDbObjectPointer<AcDbEntity> spEnt(objId,AcDb::kForRead);
        if(spEnt.openStatus() != Acad::eOk)
            return;

        AcDbObjectId dictId = spEnt->extensionDictionary();

        if(!dictId.isNull())
        {
            AcDbObjectPointer<AcDbDictionary> spDict(dictId,AcDb::kForRead);
            if(spDict.openStatus() == Acad::eOk)
            {
                PrintDictionary(spDict.object());
            }
        }
        else
        {
            acutPrintf(_T("n 没有扩展记录数据"));
        }
    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!