Select to view content in your preferred language

how to get the hightlighted layers in TOC ?

355
2
11-07-2023 09:47 PM
pyfans
by
New Contributor II

How to get  the selected layers in the TOC (i.e. clicked via the mouse and is now highlighted)  with arcpy? thank you.

Tags (3)
0 Kudos
2 Replies
DanPatterson
MVP Esteemed Contributor

there is no arcpy functionality to do this


... sort of retired...
0 Kudos
StaticK
MVP

You could check them (uncheck the others you don't want) and then use the lyr.visible property to separate them.

aprx = arcpy.mp.ArcGISProject(r'C:\.aprx')
m = aprx.listMaps("Map")[0]
checked_layers = [lyr for lyr in m.listLayers() if lyr.visible]

#for lyr in m.listLayers():
#    if lyr.visible:
#        arcpy.AddMessage(f"{lyr.name} is selected.")