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
Any ideas ?
Regards, Evan
Hi Evan,
EvanH said:Any ideas ?
This code works fine in C#. I assume you should be able to adapt it to C++ API ;-)
DgnFile dgnFile = Session.Instance.GetActiveDgnFile(); using (FileLevelCache levelCache = dgnFile.GetLevelCache()) using (EditLevelHandle levelHandle = levelCache.CreateLevel("my new level")) { if (levelHandle.IsValid) { LevelDefinitionLineStyle definition = new LevelDefinitionLineStyle(3, null, dgnFile); levelHandle.SetByLevelLineStyle(definition); LevelCacheErrorCode result = levelCache.Write(); } }
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
Hi Jan
Thank you very much for your reply.
Your code looks like my code adapted to C#, but the problem is when I want to set the ByLevelLineStyle for the new level. The only way to do this (as far as I can see) is to use the SetByLevelLineStyle method that requires an LsEntryCP as first parameter. The only way to get that is through LineStyleManager::ResolveLineStyle and it doesn't work correctly. It must have been working when I developed the code years back (I don't remember the CE update number).
Evan
EvanH said:SetByLevelLineStyle method that requires an LsEntryCP as first parameter.
Cannot be LevelDefinitionLineStyle casted to LsEntry?
Interesting thing is that NET API is nothing else than a wrapper around native API, but methods parameters are different (and not much can be understood from aseembly code).
EvanH said:It must have been working when I developed the code years back (I don't remember the CE update number).
It is true that there is no way how to obtain line style entry for standard MicroStation line styles 0 - 7. LevelMap does not contain these definitions, when iterated (at least what I see in NET API).
Robert Hook any idea why?
Jan Šlegr said:It is true that there is no way how to obtain line style entry for standard MicroStation line styles 0 - 7
I found this comment in MicroStationAPI help under LineStyleManager: If the style number is in the range STYLE_MinLineCode to STYLE_MaxLineCode, the LineStyleManager does not retrieve an LsDefinition. Handling of these line styles is strictly defined and does not require an LsDefinition.
LineStyleManager
enum LsKnownStyleNumber { STYLE_MinLineCode = 0, STYLE_MaxLineCode = 7, STYLE_ByLevel = 0x7fffffff, STYLE_ByCell = 0x7ffffffe, STYLE_Invalid = 0x7fffff00 }
Regards, Jon Summers LA Solutions
Hi Jon
I've read that comment too but in order to set the ByLevel linestyle using the SetByLevelLineStyle method you need a LSEntryCP
Ragards, Evan
EvanH said: in order to set the ByLevel linestyle using the SetByLevelLineStyle method you need a LSEntryCP
I agree that's a conundrum. What happens if you pass STYLE_MinLineCode (or some other integer 0..7) instead of an LSEntry?
STYLE_MinLineCode
LSEntry
If I use these lines of code:
int ls = 3; elh.SetByLevelLineStyle((LsEntryR)ls, NULL, *ISessionMgr::GetActiveDgnModelRefP()->GetDgnFileP());
then MicroStation chrashes...