Sorting Layers with Python

Discussion created by flederfauz on May 12, 2011
Latest reply on May 13, 2011 by flederfauz

I want to write a code that sorts my layers in a map in a certain order. The order shall be exactly like in a "master.mxd" where i loaded all layers and sorted them. The tool shall be used for different maps so that not all layers might be in the map where i run the code.
In my mind there are the following steps.

import arcpy
#Make new lists called CurrentLyr and MasterLyr
CurrentLyr =[]
MasterLyr =[]
#Defining Map and Dataframe of Master map
mxd = arcpy.mapping.MapDocument(r"C:/Python/Master.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
#Append all Layers in the list
MasterLyr.append (arcpy.mapping.ListLayers(mxd, "", df):)
#Defining Map and Dataframe of CurrentMap
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd, "")[0]
#Append all Layers in the list
CurrentLyr.append (arcpy.mapping.ListLayers(mxd, "", df):)
#Step through each Master layer
for i in MasterLyr:
#compare MasterLyr with CurrentLyr
  if cmp(MasterLyr,CurrentLyr)= true
#Add Layer to current map
arcpy.mapping.AddLayer(df, "", "bottom")

Thats my first Python Code ever so please be patient.
Any ideas or pieces of code?

best regards