ArcGIS Pro version 2.4.0
I have a Python Toolbox script to reorder the layers in my Current Map as follows:
currentProject = arcpy.mp.ArcGISProject("CURRENT")
currentMap = currentProject.listMaps()[0] # this assumes one map
layers = currentMap.listLayers()
#LGA the very bottom
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
LGA_LYR= currentMap.listLayers('LGA_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,LGA_LYR,"AFTER") # LGA below Spatial
#Property
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
PROPERTY_LYR= currentMap.listLayers('PROPERTY_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,PROPERTY_LYR,"AFTER") #Prop below spatial
# 13 UGB_LYR All UGB line work that overlaps the LGA Layer
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
UGB_LYR = currentMap.listLayers('UGB_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,UGB_LYR,"BEFORE") #above
# 12 HERITAGE_LYR Join between SPATIALDATA and excel HEADERS
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
HERITAGE_LYR = currentMap.listLayers('HERITAGE_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,HERITAGE_LYR,"BEFORE") #above
# 11 TOP_10_LYR Top 10 Sales
SPATIALDATA_LYR= currentMap.listLayers('SPATIALDATA_LYR')[0]
TOP_10_LYR = currentMap.listLayers('TOP_10_LYR')[0]
currentMap.moveLayer(SPATIALDATA_LYR,TOP_10_LYR,"BEFORE") #above
returnThe Layers are being moved but the results seem to be quite random and the order in my debugging doesn't match the order shown in the Drawing Order pane