Error with arcpy.mapping.ListLayers - Please Help

Discussion created by gis_tech on Dec 27, 2012
Latest reply on Aug 26, 2014 by scribekey
Hello, everyone. I have a layer file that points at a FeatureClass. This FeatureClass periodically receives new data. I need to update the layer file so that it recognizes the new data.

I'm trying to use the code found at: as a starting point but it's erroring out saying "AttributeError: 'Layer' object has no attribute 'symbology'"

Ive been grinding on this for a week now and I'm totally stumped here. The layer file does have symbology set up (see attached screenshot), so I've no idea what the problem is. I'm in desperate need of help and would appreciate any suggestions.

My code is as follows:

import arcpy, os
from arcpy import env

env.workspace = os.getcwd()

mxd = arcpy.mapping.MapDocument(env.workspace + r"\CoastalCurrentsData.mxd")

# Dataframe stuff - perform an arcpy.mapping UpdateLayer (using the above pre-authors layer file)
df = arcpy.mapping.ListDataFrames(mxd, "CoastalCurrentsData")[0]
updateLayer = arcpy.mapping.ListLayers(mxd, "RecentData", df)[0]
sourceLayer = arcpy.mapping.Layer(env.workspace + r"\USWC_1km_WGS_1984.lyr")
arcpy.mapping.UpdateLayer(df, updateLayer, sourceLayer, True)

# Refresh the layers unique value symbology so that it is referencing the current data

lyr = arcpy.mapping.ListLayers(mxd, "RecentData", df)[0] # HERE'S WHERE THE ERROR HAPPENS #######