Hi!, I need to get the layer id within a map in ArcGIS Pro. It need to be done with Python, but can't find the way to do it. Any idea ? Impossible ?
Solved! Go to Solution.
Ah I see, yes you can get that:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyrs = m.listLayers()
for lyr in lyrs:
print(lyr.getDefinition("V3").serviceLayerID)
Have a look at CIM access, it's quite useful, there is much more you can do with it besides this
Take a look at arcpy.mp, I think this gets you what you want:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyrs = m.listLayers()
[(i, lyr.name) for i, lyr in enumerate(lyrs)]
returns
[(0, 'TestLine'), (1, 'TestPoint'), (2, 'TestPoint_Raster'), (3, 'TestPoly'), (4, 'TestPoint'), (5, 'World Topographic Map'), (6, 'World Hillshade')]
Thanks for the info, but that "id" is just the order within the project. I look to get the ID that is attached to the layer within the properties.
Ah I see, yes you can get that:
aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps()[0]
lyrs = m.listLayers()
for lyr in lyrs:
print(lyr.getDefinition("V3").serviceLayerID)
Have a look at CIM access, it's quite useful, there is much more you can do with it besides this
That was it! thanks!