www.mxdraw.com
内容索引主面
前一个向上下一个
McDbObject::createExtensionDictionary 方法

给对象创建一个扩展字典

C++
Mcad::ErrorStatus createExtensionDictionary();

如果成功返回Mcad::eOk

例如:sampleeditedit.sln中写扩展记录的例子

    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;
    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!