Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Error with arcpy.mapping.ListLayers - Please Help

$
0
0
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: http://resources.arcgis.com/en/help/...000003p000000/ 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:

Code:

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 #######

lyr.symbology.addAllValues()

arcpy.RefreshActiveView()
arcpy.RefreshTOC()

Attached Thumbnails
Click image for larger version

Name:	CoastalCurrentsScreenshot.JPG‎
Views:	N/A
Size:	21.2 KB
ID:	20210  

Viewing all articles
Browse latest Browse all 2485

Trending Articles