newell.kate

"IndexError: list index out of range" - when trying to Update Layer in ArcPy

Discussion created by newell.kate on Oct 5, 2011
Latest reply on Oct 8, 2011 by jbarrette-esristaff
Hi!
I am trying to run (what I thought) was a very simple script that updates the symbology in a Layer File based on another layer file. Being very new to Python, I "lifted" some example code straight from the ArcGIS10 help ( http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/UpdateLayer/00s30000003p000000/ )
The layer file to be updated in my map document is part of a grouped layer file within a grouped layer file.
I keep getting an IndexError and I have no idea why!?! There is only one dataframe (Layers). Any help is greatly appreciated!

Here is my code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"N:\Templates\v10\Base Maps\A_Portrait.mxd")
df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "Base Map Layers\Bay, Lakes & Streams", df)[0]
sourceLayer = arcpy.mapping.Layer(r"N:\Users\ke\Bay, Lakes & Streams.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)
mxd.save()
del mxd, sourceLayer


and this is the error message that I get:
====
>>>
Traceback (most recent call last):
File "N:\Users\ke\ArcPyMapping\UpdateLayerFile.py", line 4, in <module>
updateLayer = arcpy.mapping.ListLayers(mxd, "Base Map Layers\Bay, Lakes & Streams", df)[0]
IndexError: list index out of range

Outcomes