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

返回命名对象字典

C++
Mcad::ErrorStatus getNamedObjectsDictionary(McDbDictionary*& pDict, McDb::OpenMode mode);
参数 
说明 
McDbDictionary*& pDict 
返回的字典指针 对象的打开方式 

如果成功返回Mcad::eOk,如果传递的数据非法则返回Mcad::eInvalidInput

例如:读取数据命名对象字典中所有数据

    LPCTSTR
        CTestCommands::bytesToHexStr(char* buffer, int len, CString& hexStr)
    {
        unsigned char k;
        int j;
        CString tmpStr;

        hexStr.Empty();    // make sure nothing in it yet since we are concatenating it

        for (j=0;j<len;j++) {
            k = static_cast<unsigned char>(buffer[j]);
            tmpStr.Format(_T("%02hX"), k);
            hexStr += tmpStr;
        }
        return hexStr;
    }


    int
        CTestCommands::dxfCodeToDataType(int resType)
    {
        if ((resType >= 0) && (resType <= 9))
            return RTSTR;
        else if ((resType >= 10) && (resType <= 17))
            return RT3DPOINT;
        else if ((resType >= 38) && (resType <= 59))
            return RTREAL;
        else if ((resType >= 60) && (resType <= 79))
            return RTSHORT;
        else if ((resType >= 90) && (resType <= 99))
            return RTLONG;
        else if ((resType == 100) || (resType == 101) || (resType == 102) ||(resType == 105))
            return RTSTR;
        else if ((resType >= 110) && (resType <= 112))
            return RTSTR;
        else if ((resType >= 140) && (resType <= 149))
            return RTREAL;
        else if ((resType >= 170) && (resType <= 179))
            return RTSHORT;
        else if ((resType >= 210) && (resType <= 219))
            return RT3DPOINT;
        else if ((resType >= 270) && (resType <= 299))
            return RTSHORT;
        else if ((resType >= 300) && (resType <= 309))
            return RTSTR;
        // 310-319为二进制数据
        else if ((resType >= 310) && (resType <= 319))
            return resType;
        else if ((resType >= 320) && (resType <= 369))
            return RTENAME;
        else if ((resType >= 370) && (resType <= 379))
            return RTSHORT;
        else if ((resType >= 380) && (resType <= 389))
            return RTSHORT;
        else if ((resType >= 390) && (resType <= 399))
            return RTENAME;
        else if ((resType >= 400) && (resType <= 409))
            return RTSHORT;
        else if ((resType >= 410) && (resType <= 419))
            return RTSTR;
        else if (resType == 1004)
            return resType;        // binary chunk
        else if ((resType >= 999) && (resType <= 1009))
            return RTSTR;
        else if ((resType >= 1010) && (resType <= 1013))
            return RT3DPOINT;
        else if ((resType >= 1038) && (resType <= 1059))
            return RTREAL;
        else if ((resType >= 1060) && (resType <= 1070))
            return RTSHORT;
        else if ((resType == 1071))
            return RTLONG;
        else if ((resType < 0) || (resType > 4999))
            return resType;
        else
            return RTNONE;
    }

    void
        CTestCommands::dxfToStr(const resbuf* rb, CString& dxfCodeStr, CString& valueStr)
    {
        int dataType = dxfCodeToDataType(rb->restype);
        dxfCodeStr.Format(_T("%d"), rb->restype);

        CString tmpStr;

        switch (dataType) {
        case RTSHORT:
            valueStr.Format(_T("%d"), rb->resval.rint);
            break;
        case RTLONG:
            valueStr.Format(_T("%ld"), rb->resval.rlong);
            break;
        case RTREAL:
            valueStr.Format(_T("%g"), rb->resval.rreal);
            break;
        case RTSTR:
            if (rb->resval.rstring == NULL)
                valueStr = _T("(NULL)");
            else
                valueStr.Format(_T(""%s""), rb->resval.rstring);
            break;
        case RT3DPOINT:
            valueStr.Format(_T("(%g, %g, %g)"), rb->resval.rpoint[X],
                rb->resval.rpoint[Y], rb->resval.rpoint[Z]);
            break;
        case RTPOINT:
            valueStr.Format(_T("(%g, %g)"), rb->resval.rpoint[X], rb->resval.rpoint[Y]);
            break;

        case -6:
            valueStr = _T("Extension Dictionary");
            break;
        case -5:
            valueStr = _T("Persistent Reactors");
            break;
        case -4:
            valueStr.Format(_T("Conditional Operator: "%s""), rb->resval.rstring);
            break;
        case -3:
            valueStr = _T("Start of Xdata");
            break;
        case -2:
            valueStr.Format(_T("<Entity Name Reference: %8lx>"), rb->resval.rlname[0]);
            break;
        case -1:
        case RTENAME:
            if ((rb->restype >= 330 )&& (rb->restype < 340))
                valueStr.Format(_T("<Soft Pointer: %8lx>"), rb->resval.rlname[0]);
            else if((rb->restype >= 340) && (rb->restype < 350))
                valueStr.Format(_T("<Hard Pointer: %8lx>"), rb->resval.rlname[0]);
            else if((rb->restype >= 350) && (rb->restype < 360))
                valueStr.Format(_T("<Soft Ownership: %8lx>"), rb->resval.rlname[0]);
            else if((rb->restype >= 360) && (rb->restype < 370))
                valueStr.Format(_T("<Hard Ownership: %8lx>"), rb->resval.rlname[0]);
            else if((rb->restype >= 390) && (rb->restype < 399))
                valueStr.Format(_T("<Hard Pointer: %8lx>"), rb->resval.rlname[0]);
            else
                valueStr.Format(_T("<Entity Name: %8lx>"), rb->resval.rlname[0]);
            break;
        case RTPICKS:
            valueStr.Format(_T("<Selection Set: %8lx>"), rb->resval.rlname[0]);
            break;
        case RTLB:
            valueStr = _T("List Begin");
            break;
        case RTLE:
            valueStr = _T("List End");
            break;
        case RTNIL:
            valueStr = _T("NIL");
            break;
        case RTT:
            valueStr = _T("T");
            break;
        default:
            {
                if (dataType == 1004 || (dataType >= 310 && dataType <= 319) ) 
                {
                    // 二进制数据。
                    valueStr.Format(_T("Binary Chunk: "%s""),
                        bytesToHexStr(rb->resval.rbinary.buf,
                        rb->resval.rbinary.clen, tmpStr));

                }
                else
                {
                    valueStr = _T("*Unknown*");
                }
            }
            break;
        }
    }

    void
        CTestCommands::printResbufChain(resbuf* const rb)
    {
        CString dxfCodeStr, valueStr, tmpStr;
        resbuf* tmp = rb;
        while (tmp) {
            dxfToStr(tmp, dxfCodeStr, valueStr);
            tmpStr.Format(_T("n(%s . %s)"), dxfCodeStr, valueStr);
            acutPrintf(static_cast<LPCTSTR>(tmpStr));
            tmp = tmp->rbnext;
        }
    }

    void CTestCommands::ReadNamedObjectsDictionary()
    {
        {
            // 把字典中所有的数据都输出
            AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
            AcDbObjectPointer<AcDbDictionary> spDict(pDb->namedObjectsDictionaryId(),AcDb::kForRead);
            if(spDict.openStatus() == Acad::eOk)
            {
                PrintDictionary(spDict.object() );
            }
        }


        // 读取指定的数据.
        AcDbDictionary *pNamedobj;
        AcDbDatabase *pDb = acdbHostApplicationServices()->workingDatabase();
        if(pDb->getNamedObjectsDictionary(pNamedobj, AcDb::kForRead) != Acad::eOk)
        {
            return ;
        }
        AcDbDictionary *pDict;
        if(pNamedobj->getAt(_T("ESTATE_DICT"), (AcDbObject*&)pDict,AcDb::kForRead) != Acad::eOk)
        {
            pNamedobj->close();
            return ;
        }
        pNamedobj->close();
        //得到数据字典LAYERRECORD
        AcDbXrecord *pXrec;
        if(pDict->getAt(_T("LAYERRECORD"), (AcDbObject*&)pXrec,AcDb::kForRead) != Acad::eOk)
        {
            pDict->close();
            return ;
        }
        pDict->close();

        // 把记录中数据输出.

        struct resbuf *pRbList;
        pXrec->rbChain(&pRbList);
        printResbufChain(pRbList);
        acutRelRb(pRbList);

        pXrec->close();

    }
Copyright (c) 2010. All rights reserved.
你认为该帮助怎么样? 发送反馈信息!