I used this code from this question here: Remove item from legend using ArcPy?
However I keep getting an error at the following line:
legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT")[0]
that says:
AttributeError: 'list' object has no attribute 'listLegendItemLayers'
However, I clearly have a legend in the mxd's.
import arcpy
import arcpy.mapping
import os
import sys
from arcpy import env
import string
env.workspace = r"C:\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
print mxdname
mxd = arcpy.mapping.MapDocument(r"C:\Project\\" + mxdname)
legend = arcpy.mapping.ListLayoutElements(mxd,"LEGEND_ELEMENT")[0]
for lyr in legend.listLegendItemLayers():
if lyr.name == "atikot":
legend.removeItem(lyr)
print 'remove'
mxd.save()
del mxd