i try to sort layers in the TOC, in ascending or by name alphbetical with this code:
mxd = arcpy.mapping.MapDocument(r"D:\desktop\Project\project.mxd")
df = arcpy.mapping.ListDataFrames(mxd) # Assuming one data frame
group_lyr = [lyr for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isGroupLayer] # The temp group layer should be the only one
lyr_names = sorted(lyr.name for lyr in arcpy.mapping.ListLayers(mxd) if lyr.isFeatureLayer)
for name in lyr_names:
arcpy.mapping.MoveLayer(df, group_lyr, arcpy.mapping.ListLayers(mxd, name), "BEFORE")
print name +' sorted'
land use sorted
but the TOC do't sorted. For clarity, i saw this question in arcgis 10.0 - Arc GIS 10.1 - How to sort Layers ascending at TOC in "List by drawing order" - Geogra...
I work with arc view 10.3. I know it possible with extension, but i have no extensions.
Is it possible to do it with python?
Solved! Go to Solution.
also, it makes little sense to sort things alphabetically... for example
... landuse, river in this scenario, you could have agricultural land over top of the river
... fire station, ownership .... where did the fire station go?
... bridge, river .... the Chunnel?
Order things by geometry first, then conceptually within each grouping to ensure that you don't obliterate features that should be seen