Monday, July 11, 2011

Moving Layer Position in Table of Contents

In the arcpy.mapping module there is a function called MoveLayer() which allows developers to move a layer to a specific location within a data frame or group layer in a map document.  It does not give you the ability to move layers between data frames and the moved layer and reference layer must reside in the same data frame as well.

To move layers between data frames, use the Add Layer, Insert Layer and Remove Layer functions.

Example: Move Layer Position

import arcpy
from arcpy import mapping
for lyr in mapping.ListLayers(mxd,"",df):
   if == "layer1":
      moveLayer = lyr
   if == "layer2":
      refLayer = lyr
del mxd

The final result will be that layer1 is below layer2: