private static void ImportNestedFilters( _AcLm.LayerFilter srcFilter, _AcLm.LayerFilter destFilter, _AcDb.Database srcDb, _AcDb.Database destDb, bool copyLayer, _AcEd.Editor ed) { using (_AcDb.Transaction tr = srcDb.TransactionManager.StartTransaction()) { _AcDb.LayerTable lt = tr.GetObject(srcDb.LayerTableId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTable; foreach (_AcLm.LayerFilter sf in srcFilter.NestedFilters) { _AcDb.IdMapping idmap = new _AcDb.IdMapping(); if (copyLayer) { // Get the layers to be cloned to the dest db. // Only those that are pass the filter _AcDb.ObjectIdCollection layerIds = new _AcDb.ObjectIdCollection(); foreach (_AcDb.ObjectId layerId in lt) { _AcDb.LayerTableRecord ltr = tr.GetObject(layerId, _AcDb.OpenMode.ForRead, false) as _AcDb.LayerTableRecord; if (sf.Filter(ltr)) { layerIds.Add(layerId); } } // clone the layers to the dest db if (layerIds.Count > 0) { srcDb.WblockCloneObjects( layerIds, destDb.LayerTableId, idmap, _AcDb.DuplicateRecordCloning.Replace, false); } } // Find if a destination database already // has a layer filter with the same name _AcLm.LayerFilter df = null; foreach (_AcLm.LayerFilter f in destFilter.NestedFilters) { if (f.Name.Equals(sf.Name)) { df = f; break; } } if (df == null) { if (sf is _AcLm.LayerGroup) { // create a new layer filter group // if nothing found _AcLm.LayerGroup sfgroup = sf as _AcLm.LayerGroup; _AcLm.LayerGroup dfgroup = new _AcLm.LayerGroup(); ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter-Gruppe {0}.", sf.Name)); dfgroup.Name = sf.Name; df = dfgroup; if (copyLayer) { _AcLm.LayerCollection lyrs = sfgroup.LayerIds; foreach (_AcDb.ObjectId lid in lyrs) { if (idmap.Contains(lid)) { _AcDb.IdPair idp = idmap[lid]; dfgroup.LayerIds.Add(idp.Value); } } } destFilter.NestedFilters.Add(df); } else { // create a new layer filter // if nothing found ed.WriteMessage(string.Format(CultureInfo.CurrentCulture, "\nImportiere Layerfilter {0}.", sf.Name)); df = new _AcLm.LayerFilter(); df.Name = sf.Name; df.FilterExpression = sf.FilterExpression; destFilter.NestedFilters.Add(df); } } // Import other filters ImportNestedFilters(sf, df, srcDb, destDb, copyLayer, ed); } tr.Commit(); } }