显示元素的描述(Display Element's Description)


我们在编程过程中能容易地得到元素的ElementID和Type,但这个Type是一个数字,仅从该数字很难知道它到底是个什么类型的元素,还需要通过手工查SDK中的头文件来确定。那能否在编程中直接以文字来显示这个元素的类型呢?答案是肯定的。

如下代码查看当前DGN中的数据字典部分,列出数据字典中控制元素的名称、类型及其元素ID。该代码在MicroStation CONNECT版EAP3上调试通过,如果您的开发环境仍在MicroStation V8i下,本代码虽不能直接使用,但也应该具有借鉴意义。

void fileAnalyze(WCharCP unparsed)
    {
    DgnFileP pDgnFile = ISessionMgr::GetManager().GetActiveDgnFile();
    DgnModelR dictionaryModel = pDgnFile->GetDictionaryModel();
    WString myString, elDescr;
    PersistentElementRefList *pElemRefList = dictionaryModel.GetControlElementsP();
    for (PersistentElementRefP const& elemRef : *pElemRefList)
        {
        ElementHandle eh(elemRef);
        eh.GetHandler().GetDescription(eh, elDescr, 100);
        myString.Sprintf(L"ElemType = %s(%d), ElementId=%d", 
            elDescr.GetWCharCP(), elemRef->GetElementType(), elemRef->GetElementId());
        mdlDialog_dmsgsPrint(myString.GetWCharCP());
        }
    }

运行结果如下:

核心函数就是ElementHandle.GetHandler().GetDescription()。