arcpy.mapping.MoveLayer(df, "Contours 10m - MARANOA REGIONAL", "SPOT 2009 Image Date", "BEFORE")
for lyr in layerlist: if lyr.name == "Contours 10m - MARANOA REGIONAL": moveLayer = lyr arcpy.AddMessage(moveLayer) if lyr.name == "SPOT 2009 Image Date": refLayer = lyr arcpy.AddMessage(refLayer) arcpy.mapping.MoveLayer(df, refLayer, moveLayer, "BEFORE")
mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd)[0] arcpy.mapping.MoveLayer(df, "Contours 10m - MARANOA REGIONAL", "SPOT 2009 Image Date", "BEFORE") arcpy.RefreshTOC() arcpy.RefreshActiveView() mxd.save() del mxd
Though I realise by this time you're probably well past this problem, in case it's helpful to anyone else I'm guessing re-defining the layer list is running arcpy.mapping.ListLayers() again - that's certainly what worked for me.
I was having this trouble myself - I was adding a new layer in my script and then wanted to reposition it, but it wasn't working. My new layer replaced an old layer of the same name. To save processing, I had defined the layer list once and was re-using it to pull out the layer object that I needed to move. So my script was returning a layer object to me, but it was the old version of the layer, which of course didn't exist any more, thus the error message. Using arcpy.mapping.ListLayers() again to pick up the new layer solved the problem.