0

I have an mxd file that I've loaded into ArcMap. When finished loading, there are several layers; some of which that have multiple feature classes. The end result is listing all the filepaths/locations/source of each feature class, but for now, I just need to know how to list all the feature classes that are loaded. And when I say list, they can really just be output to the screen via message boxes. I know I'll need to loop through each layer, but utilizing the right interface and accessing ArcMaps properties is where I get lost.

Any help on this would be greatly appreciated. I'm still learning ArcObjects and how it all works and in desperate need of help. Thanks in advance.

user1898629
  • 329
  • 1
  • 4
  • 22
  • A single _layer_ only pulls data from a single feature class; a _group_ of layers may have multiple layers (and multiple feature classes). I apologize if this may seem picky, but the terminology is important :) – Erica Mar 30 '16 at 11:00

1 Answers1

0

This would be an example in C# to loop through all layers and if it's a feature layer, get until the workspace to get the path or whatever from it:

/* Make a list of all feature classes. */
List<ILayer> layers_list = new List<ILayer>();
IMap map = get_map();
IEnumLayer enumLayer = map.get_Layers(null, true);
ILayer layer = null;
while (layer = enumLayer.Next() != null) {
    // we're looking for a feature class only
    if (layer is IFeatureLayer) {
        try {
            IFeatureClass fclass = ((IFeatureLayer)layer).FeatureClass;
            IFeatureLayer featureLayer = (IFeatureLayer)layer;
            // Get the dataset and workspace of the feature class
            IDataset ds = (IDataset)fclass;
            IWorkspace ws = (IWorkspace)ds.Workspace;
            // Do something with the workspace, like getting the path or
            // whatever...
        } catch (Exception e) {
            MessageBox.Show("Layer ' " + layer.Name + "': \n\n" + e.Message);
        }
    }
}
andzep
  • 1,877
  • 24
  • 35