8

I am working in an ArcMap session, I've checked the option to get an ID for each of the layers in my document, so anyone has it.

enter image description here

Now, what I need is a way to get these values within a python script (to copy that automatically in a table): there's no such information in the layer's properties reached by a describe, nor from the .mapping module.

6
  • 4
    The property DSID in arcpy.describe returns the ID of the data set. have you tried that? An example would be desc = arcpy.Describe("some layer") then desc.DSID Commented Jan 4, 2016 at 13:44
  • What version of ArcGIS are you using? Commented Jan 4, 2016 at 17:34
  • Hy Dan, the problem is that I need the ID of a layer, which doesn't seem to have the property "ID" accessible from with the describe function.. Commented Jan 5, 2016 at 14:51
  • I'm working with a 10.3.1 advanced version. Commented Jan 5, 2016 at 14:53
  • 2
    It's not about a particular layer or feature class, but something general. To turn on the ids check the option ("Allow assignment [...]") in the data frame's general tab. Commented Jul 2, 2016 at 8:47

2 Answers 2

4

In ArcGIS Pro you can do this:

cim_version = 'V2'
aprx = arcpy.mp.ArcGISProject(aprx_file)
map0 = aprx.listMaps()[0]
lyr0 = map0.listLayers()[0]
def0 = lyr0.getDefinition(cim_version)
# serviceLayerID will be -1 if "allow assign. unique ids to layers"
# was not check on the Data Frame properties
# in that case, serviceLayerID are in order from 0 -> len(layers) - 1
# & includes GroupLayers (can check lyr0.isGroupLayer, etc)
serviceLayerID = def0.serviceLayerID
1

After testing this in ArcGIS 10.3, and according to the documentation available for Layer and Describe in arcpy, and also this thread: https://geonet.esri.com/thread/178341, this functionality does not yet exist. You cannot access the layer ID from arcpy. You may be able to access it through ArcObjects if you have the knowledge.

As a workaround, can you enter the ID into the Credits or Description fields? You can access both of these fields through arcpy.

1
  • Goodmorning Jbalk, as you said I've written the Id layer in a table's field by using the Field Calculator tool (manually checking each layers' value). Thanks a lot for the advice, ArcObjects are my next stop.. Commented Sep 22, 2016 at 10:40

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.