AnsweredAssumed Answered

Move Layer

Question asked by CCweedcontrol on Sep 8, 2017
Latest reply on Sep 8, 2017 by rvburton

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 == "Taxparcels1":
        moveLayer = lyr
    if == "Sections":
        refLayer = lyr
arcpy.mapping.MoveLayer(df, refLayer, moveLayer, "BEFORE")
#mxd.saveACopy(r"C:\Temp\Split MXD2.mxd")
del mxd



Runtime error 
Traceback (most recent call last):
  File "<string>", line 12, in <module>
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\", line 182, in fn_
    return fn(*args, **kw)
  File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\", line 1677, in MoveLayer
    assert move_c is not None, 'Did not find move layer.'
AssertionError: Did not find move layer.