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
  • 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();
                 }
             }
    }

Children