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
  • One more questing. 

                foreach (var dgnFilePath in dgnFiles)
                {
                    using (DgnDocument targetDgnDocument = DgnDocument.CreateForLocalFile(dgnFilePath))
                    using (DgnFileOwner dgnFileOwner = DgnFile.Create(targetDgnDocument, DgnFileOpenMode.ReadOnly))
                    {
                        dgnFileOwner.DgnFile.LoadDgnFile(out StatusInt statusInt);
                        DgnFile dgnFile = dgnFileOwner.DgnFile;
                        DgnModel dgnModel = dgnFile.LoadRootModelById(out StatusInt loadDetails, dgnFile.DefaultModelId);
                        ActiveDgnFile.CreateNewModel(out DgnModelStatus error, dgnModel.ModelName, DgnModelType.Normal, true, dgnModel);
                        ModelId newDgnModelId = ActiveDgnFile.FindModelIdByName(dgnModel.ModelName);
                        DgnModel newDgnModel = ActiveDgnFile.LoadRootModelById(out StatusInt errorDetails, newDgnModelId);
                        DgnFile.CopyModelContents(newDgnModel, dgnModel);
                    }
                }

    I have this to create my dgn-file with all the models from a folder containing several dgn-files and it works.

    But i would like to iterate through all models, activate them and remove levels ending with " V".

    Something like this:

        ModelIndexCollection models = dgnFile.GetModelIndexCollection();
        foreach (ModelIndex model in models)
        {
            //Delete the levels in the model...
            //maybe with keyin? like: Session.Instance.Keyin("level element delete \"* V\"")
        }

    Or do you have any suggesting?

    My goal is to create a cell-library with just models without the levels ending with " V"

    And also a cell-library with just models ending with " V". So 2 different cell-library.

Children