I have this:
using (FileLevelCache levelCache = ActiveDgnFile.GetLevelCache()) { LevelHandleCollection levelHandles = levelCache.GetHandles(); foreach (LevelHandle level in levelHandles) { if (level.Name.EndsWith(" P") || level.Name.EndsWith(" L")) {levelCache.RemoveLevel(null, level); levelCache.Write(); } } }
But it dont remove the levels. I think I need to remove the elements assosiated with the levels before removing the levels. But I dont know how...
Can anyone help?
Samuel Wiklund said:I need to remove the elements assosiated with the levels
Enumerate the DGN elements of a DGN model. Here's a C# example.
For each element, if it's graphical, get its level. Compare the level name with your criteria. Remove each element that passes your filter.
Regards, Jon Summers LA Solutions
Im sorry, this is the first time for me asking for help.
Microstation Connect Update 16
Version 10.16.00.80
Using C#
Code:
DgnFile ActiveDgnFile = Session.Instance.GetActiveDgnFile();
using (FileLevelCache levelCache = ActiveDgnFile.GetLevelCache()) { LevelHandleCollection levelHandles = levelCache.GetHandles(); foreach (LevelHandle level in levelHandles) { if (level.Name.EndsWith(" P") || level.Name.EndsWith(" L")) { levelCache.RemoveLevel(null, level); levelCache.Write(); } } }
Sorry, but when you ignore this forum best practices constantly , do not expect positive response:
Please correct the issues!
Samuel Wiklund said:But I dont know how...
And did you try to search this forum, code examples delivered with MicroStation SDK or any from SDK documentation? They contain the answer for sure, because to delete element is crucial task. And at last, but not least, IntelliSense in Visual Studio shows you DeleteFromModel() method exists for every Element.
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point