Remove Elements in dgn-file with specific name

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?

Parents Reply
  • Is it something to do with the Properties of the element thats "Not Modified"?

    Again, lack of knowledge (that cannot be substituted by discussions, but solved only by some training).

    Modified is an element property, showing whether it was modified (at least once) from time it was created.

    Maybe there is a better way to do the if-sentens to match the levels with the elements.

    There is no better way, but the mandatory condition is you must understand how DGN format is designed and how API works. I wrote several times you must analyze, what Element (sub)class is returned, when SmartSolid is found, and also what ElementID:

    • In DGN, SmartSolid is just a cell (I wrote it already). Cell begins with cell (complex) header, which has no level assigned.
    • In MicroStation (as well as in API), SmartSolid is element, represented in API (I guess) BrepCellHeader class.

    So you must analyze what elements are iterated and adapt the evaluation accordingly to their types. Because complex headers have no element, you must decide what it means "SmartSolid is in particular level" (e.g. all elements/content are in the same level) and to write proper code.

    Of course, you can use workaround and to use key-in to delete specific level.

    With regards,

      Jan

Children