private Dictionary <int, ILayer> ReadMapLayers(bool onlySelectedFeatures, bool onlyCurrentExtent, bool highlightedLayerOnly) { List <ILayer> layers = null; if (highlightedLayerOnly) { if (this.MxDocument.SelectedLayer != null) { layers = new List <ILayer>(); if (!this.MxDocument.SelectedLayer.Is3D()) { layers.Add(this.MxDocument.SelectedLayer); } } else { layers = this.MxDocument.SelectedItem.ToLayerList(); } } else { layers = LayerHelper.GetLayerList(this.MxDocument.FocusMap); } Dictionary <int, ILayer> exportLayers = new Dictionary <int, ILayer>(); IEnvelope extent = null; if (onlyCurrentExtent) { extent = this.MxDocument.ActiveView.Extent; } int i = 0; foreach (ILayer layer in layers) { if (layer is IFeatureLayer && !layer.Is3D()) { IFeatureLayer featureLayer = (IFeatureLayer)layer; IFeatureSelection featureSelection = (IFeatureSelection)featureLayer; bool hasSelectedFeatures = (featureSelection.SelectionSet.Count > 0); bool visibleInCurrentExtent = false; bool selectedVisibleInCurrentExtent = false; if (extent != null) { ISpatialFilter filter = new SpatialFilterClass(); filter.Geometry = extent; filter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects; visibleInCurrentExtent = featureLayer.FeatureClass.FeatureCount(filter) > 0; ICursor cursor; featureSelection.SelectionSet.Search(filter, true, out cursor); int c = 0; while (cursor.NextRow() != null) { c++; break; } selectedVisibleInCurrentExtent = (c > 0); } if (onlySelectedFeatures & onlyCurrentExtent) { if (selectedVisibleInCurrentExtent) { exportLayers.Add(++i, layer); } } else if (onlySelectedFeatures & !onlyCurrentExtent) { if (hasSelectedFeatures) { exportLayers.Add(++i, layer); } } else if (!onlySelectedFeatures & onlyCurrentExtent) { if (visibleInCurrentExtent) { exportLayers.Add(++i, layer); } } else { exportLayers.Add(++i, layer); } } } return(exportLayers); }