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
using (FileLevelCache levelCache = ActiveDgnFile.GetLevelCache()) { foreach (DgnModel dgnModel in ActiveDgnFile.GetLoadedModelsCollection()) { ModelElementsCollection elementsCollection = dgnModel.GetGraphicElements(); LevelHandleCollection levelHandles = levelCache.GetHandles(); foreach (LevelHandle level in levelHandles) { if (level.Name.EndsWith(" P") || level.Name.EndsWith(" L")) { foreach (Element el in elementsCollection) { if (level.LevelId == el.LevelId) { el.DeleteFromModel(); } } levelCache.RemoveLevel(null, level); levelCache.Write(); } } } }
Now I have this where I compare levelID. I think this might work, what do you think?
Samuel Wiklund said:I think this might work, what do you think?
I agree: it might work. Why not try it? Let us know!
It worked but I have a problem. Levels thats are of type "Smart solids" doesnt get deleted.. anyone that know why?
Samuel Wiklund said:Levels thats are of type "Smart solids" doesnt get deleted.. anyone that know why?
There is no such thing as a level of type "Smart solids".
Each graphical element is assigned a level. The level may be named "Smart solids", but that doesn't mean much — it's just a label. You could assign that level to a simple line, for example.
It's hard to provide a diagnosis without evidence. Can you post a DGN file where you have this problem?