Obtain the layer ID of an ILayer

2560
3
05-29-2014 10:37 AM
SeanNakasone
New Contributor II
Hi, what's the best way to obtain the layer ID of an ILayer?

The information below might be confusing, but I just want to provide background as to why I'm asking this question...

The closest thing I found was ILayerDescriptor.ID .  But it seems you need a Map Service object to obtain the ILayerDescriptor--all I have is an mxd document.

I guess I could loop through all layers, and just increment an integer starting from 0, and assume that the layer ID will be the same as the integer.  But that seems kinda quirky.
0 Kudos
3 Replies
SeanNakasone
New Contributor II
I'm using C# and ArcGIS for Desktop 10.2.2 .

Yes, I'm trying to find the layer index in ArcMap > Table of Contents in "List by Drawing Order" mode, so that it includes Group layers.

If there's also a way to obtain an ID that uniquely identifies a Layer instance, that might be useful too, because the indexes will change if we insert/delete layers.  But if there's no such ID, then I'll use the indexes.

I'll consider using the layer name, but it seems like multiple layers can have the same name.

I'll consider using the data source, but it seems like multiple layers can have the same data source as well.
0 Kudos
SeanNakasone
New Contributor II
Thanks for the info.  Yes, I'm already using IEnumLayer to loop through the layers.
So I'm guessing there's no ID that uniquely identifies a Layer instance, but I'll use the index .
Thanks for your help.
0 Kudos
SeanNakasone
New Contributor II
Thank you very much.  I appreciate all the suggestions...
0 Kudos