I am trying to move TOC layers with the following python code, seems simple enough. Basically i am trying to move TaxParcels1 layer above the Sections layer of my current mxd but i am not sure why i keep getting the error is it because my layers start with an upper case? Also do i have to save to a new mxd for the layer move to happen?
import arcpy
mxd = arcpy.mapping.MapDocument(r"C:\Temp\Split MXD.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
for lyr in arcpy.mapping.ListLayers(mxd, "", df):
if lyr.name.lower() == "Taxparcels1":
moveLayer = lyr
if lyr.name.lower() == "Sections":
refLayer = lyr
arcpy.mapping.MoveLayer(df, refLayer, moveLayer, "BEFORE")
#mxd.saveACopy(r"C:\Temp\Split MXD2.mxd")
del mxd<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
Error
Runtime error
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\utils.py", line 182, in fn_
return fn(*args, **kw)
File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\mapping.py", line 1677, in MoveLayer
assert move_c is not None, 'Did not find move layer.'
AssertionError: Did not find move layer.<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>