I currently doing a migration from v8i to V10 (CONNECT).

I need a substitute for mdlLevel_getIdFromElementId, which is not part of the API any more.

Any suggestions?

Best, Stefan.

  • Unknown said:
    Any suggestions?

    In the help documentation for ElementPropertiesGetter there is an example that may help.

    However, as with much of the MicroStationAPI documentation, it's hard to find.  You need to look in the Detailed Description section, then click the rather dim More... button to see that example.

    static void getLevelAndColor (ElementHandleCR eh, LevelId& level, UInt32& color)
    ElementPropertiesGetterPtr propGetter = ElementPropertiesGetter::Create (eh);
    level = propGetter->GetLevel ();
    color = propGetter->GetColor ();

    Regards, Jon Summers
    LA Solutions

  • Thanks for responding John,

    but its not exactly what I need.

    The old function returned the levelid from an element that has stored the level definition in it.

    StatusInt       mdlLevel_getIdFromElementId  
    DgnModelRefP*       modelRefOut , 
    LevelID*       pLevelIdOut , 
    DgnFileObjP       pFileObjIn , 
    ElementID       elementIdIn  
    Given a level element id, get its level-id 
    Required Header
    Required Library
    mdlbltin.lib (MicroStation Built-in)
    Return Value
    Type Description 
    StatusInt  ERROR if the element id does not represent a level element, else SUCCESS  
    Type Name Mode Description 
    DgnModelRefP*  modelRefOut  OUT  model-ref of level id  
    LevelID*  pLevelIdOut  OUT  level id  
    DgnFileObjP  pFileObjIn  IN  file obj of element id  
    ElementID  elementIdIn  IN  level element id  
    VBA Wrapper Declaration
    Declare Function mdlLevel_getIdFromElementId Lib "stdmdlbltin.dll" ( ByRef modelRefOut As Long , ByRef pLevelIdOut As Long , ByVal pFileObjIn As Long , ByVal elementIdIn As DLong ) As Long 
  • Hello stefan,
    I'd like to know the situation you use this function. How you get the level element ? Normally we specify a level by its name. The level name is unique in a DgnFile.
    Best Regards, YongAn

  • Hi YongAn,
    The level element is coming from a full dgn file scan. By its element type the software knows its a level element and tries to extract the level properties.
    Best, Stefan.
  • Hello Stefan,

    Normally, in V8i, we use mdlLevelIterator_create/mdlLevelIterator_getFirst/mdlLevelIterator_getNext/mdlLevelIterator_free to traverse all levels in a DGN file. In CONNECT, we can use LevelCache to do this. The following snippet is my test code to list all levels and its materials. Hope it is helpful.

    void listLevel(WCharCP unparsed)
        WString myString;
        DgnModelP pActiveModel = ISessionMgr::GetActiveDgnModelP();
        LevelCacheCR lvlCache = pActiveModel->GetLevelCache();
        for (LevelHandle lvlHandle : lvlCache)
            WCharCP pLvlName = lvlHandle.GetName();
            LevelDefinitionMaterial lvlMat = lvlHandle.GetByLevelMaterial();
            //LevelDefinitionMaterial lvlMat2 = lvlHandle.GetOverrideMaterial();
            ElementId elId = lvlMat.GetId();
            if (INVALID_ELEMENTID != elId && 0 != elId)
                MaterialSearchStatus matStatus;
                DgnFileP pMatDefFile = lvlMat.GetDefinitionFile();
                MaterialId matId(elId);
                MaterialCP pMat = MaterialManager::GetManagerR().FindMaterial(&matStatus, matId, *pMatDefFile, *pActiveModel, true);
                if (matStatus == MaterialSearchStatus::Success)
                      myString.Sprintf(L"%s | material=%s", pLvlName, pMat->GetName(NULL));
                else  myString.Sprintf(L"%s | Can't find material", pLvlName);
            else myString.Sprintf(L"%s | No Material", pLvlName);