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?
Thank you so much for your time helping me understand.
Is it something to do with the Properties of the element thats "Not Modified"?
Samuel Wiklund said:So I thought It might depends of the type.
Yes, but not "level type" (which does not exist), but element type.
I recommend:
Regards,
Jan
Bentley Accredited Developer: iTwin Platform - AssociateLabyrinth Technology | dev.notes() | cad.point
For some reason i did this element removed, but all others with the ending of " P". So I thought It might depends of the type.
Hi Samuel,
Samuel Wiklund said:Levels thats are of type "Smart solids" doesnt get deleted.. anyone that know why?
As Jon wrote, nothing like "Smart Solid level" exist, but what exists is MicroStation SmartSolid element (old, from V8 era).
It looks like you try to write some program without proper knowledge not only of MicroStation NET API, but also DGN format and how MicroStation creates data. Which makes situation that is not easy to give any advice.
As Jon wrote, without sharing data and explanation why you guess "Smart Solid level" exists, it's hard to guess anything.
Crucial is understand how data in DGN format are organized and difference between file / model(s) / level(s) / DGN element(s) and MicroStation (user) element(s). Smart solids are persisted (stored in DGN file) as cells with extra data attached. Moreover, cell is complex element, starting with header, that has no level (because it is not graphical element). So a question is what (what element type) your iteration finds?
With regards,
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?
Regards, Jon Summers LA Solutions
It worked but I have a problem. Levels thats are of type "Smart solids" doesnt get deleted.. anyone that know why?
Samuel Wiklund said:I think this might work, what do you think?
I agree: it might work. Why not try it? Let us know!
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?
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) { el.DeleteFromModel(); } } } } }
Samuel Wiklund said:this is the first time for me asking for help.
That's fine, but it is always recommended to check help, recommendation and best practices at first.
Samuel Wiklund said:Code:
Please use Insert > Insert code tool when sharing a code snippet!
Samuel Wiklund said:Remove Elements in dgn-file with specific name
Jon shared useful article, but as I wrote, both this forum (e.g. this discussion) and MicroStationAPI help (despite of it is about C++ API, see EditElementHandle Struct Reference chapter) provide answer an details about element lifecycle. To search should always be the first step ... and even when no right answer is found, the result is new information about MicroStation programming ;-)