i try to sort layers in the TOC, in ascending or by name alphbetical with this code:
import arcpy 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' arcpy.mapping.RemoveLayer(df, group_lyr)
>>> land use sorted river 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" - Geographic Information Sys…
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?