[Connect Upd. 15/16 MDL/C++] Set ElementLineStyle for new level

Hi

I would like to set the ElementLineStyle (using standard linestyles 0-7) for a new level. It should be a quite simple task but I got some troubles.

        LevelId lvlID = ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->ComputeHighestUsedLevelId();
		EditLevelHandle elh = ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->CreateLevel(L"TestLayer", 555, lvlID + 1);
		
		LsEntryCP ls = LineStyleManager::ResolveLineStyle(3, ISessionMgr::GetActiveDgnModelRefP()->GetDgnFileP());
		if (ls != NULL)
		{
			lifalib_dmsg("Name = %ls", ls->GetStyleName());
			elh.SetByLevelLineStyle(*ls, NULL, *ISessionMgr::GetActiveDgnModelRefP()->GetDgnFileP());
		}
		else
			lifalib_dmsg("NULL...");

		ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->Write();

My problem is that LineStyleManager::ResolveLineStyle returns NULL.

Is there another way to set the linestyle for a level ?

I've tried to use the MDL funktion mdlLevel_setElementStyle and it works just fine when working in a "normal" active design file, but some of our users often work in a model from a reference file that is "activated". In that case I have to store the fileLevelCache using:

ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->Write();

Then I can set the linestyle for the level and it seems to work just fine, but the linestyle is not saved even though that I use

mdlLevelTable_rewrite(mdlModelRef_getActive());

and / or

ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->Write();

Any ideas ?

Regards, Evan

Parents Reply
  • Hi Sagar

    If I use these few lines of code:

    EditLevelHandle elh = ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->CreateLevel(L"TestLayer", 555, LEVEL_NULL_ID);
    		LevelId lvlID = elh.GetLevelId();
    		int ls = 3;
    		ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->Write();
    		mdlLevel_setElementStyle(ISessionMgr::GetActiveDgnModelRefP(), lvlID, &ls, NULL);
    		ISessionMgr::GetActiveDgnModelRefP()->GetFileLevelCacheP()->Write();

    then the level is created and the ByLevel is set correctly, but as mentioned earlier the new linestyle is not saved when you work in an "activated" reference file...

    Regards, Evan

Children
  • Hello EvanH,

    There is an equivalent function SetByLevelLineStyle(LevelDefinitionLineStyle const&); in C++ but it doesn't expose yet. When I add it manually into below LevelCache.h file, we can use the same code as Jon's C# to implement your requirement by C++.

    https://communities.bentley.com/cfs-file/__key/communityserver-discussions-components-files/343173/LevelCache.h

    void setLinestyleForLevel()
    {
    	DgnFileP pDgnFile = ISessionMgr::GetActiveDgnFile();
    	FileLevelCacheR lvlCache = pDgnFile->GetLevelCacheR();
    	EditLevelHandle elh = lvlCache.CreateLevel(L"TestLayer", LEVEL_NULL_CODE, LEVEL_NULL_ID);
    	LevelDefinitionLineStyle ldls(3, NULL, pDgnFile);
    	elh.SetByLevelLineStyle(ldls);
    	elh.SetByLevelWeight(5);
    	lvlCache.Write();
    }



    Answer Verified By: EvanH