legend.updateItem Brings IndexError: 0

319
0
07-02-2019 07:33 AM
NathanRyan1
New Contributor

I'm working on a script to automate FEMA maps. My legend element is empty, and I need to add a shapefile (with set symbology), named S_FLD_HAZ_AR into the Legend. Here is what I have for my script so far, specifically to add the layer into the map legend. When I try to add the layer into the legend, it gives the indexerror: 0. Any help would be greatly appreciated! 

import arcpy
mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrFile = arcpy.mapping.Layer(r"S:\XXXXX\GEO_DATA\Federal\FEMA\Berkeley_FEMA\FIRM\45015C_20181210_SPintl\S_FLD_HAZ_AR.shp")
arcpy.mapping.AddLayer(df, lyrFile, "TOP")
styleItem = arcpy.mapping.ListStyleItems("ESRI.style", "Legend Items")[2]
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
lyr = arcpy.mapping.ListLayers(mxd, 'S_FLD_HAZ_AR', df)[0] 
legend.updateItem(lyr, styleItem) 

0 Kudos
0 Replies