I am trying to update an item in the legend with a style item, this is the code:

#Add Legend 
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend") [0]
legendLayers = legend.listLegendItemLayers()

#Using Style Manager to edit Legend
styleItem = arcpy.mapping.ListStyleItems("C:\\Users\\Windows\\Desktop\\test\\style manager\\noise(dBA).style", "Legend Items", "noise(dBA)")
legend.update(insertLayer, styleItem)

but I keep receiving the following error message:

legend.update(insertLayer, styleItem)
AttributeError: 'LegendElement' object has no attribute 'update'

I am a complete newbie with PyCharm and coding!

  • I doubt the issue is with pycharm. Does this work in an environment outside of pycharm?
    – Paul H
    Aug 13 '20 at 21:36
  • I'm only working within pycharm, I ended up changing my code to the following and it worked: legend.updateItem(lyr, styleItem)
    – K_atarina
    Aug 14 '20 at 21:08

Your problem is caused on the last line legend.update as there is no update method or property for the LegendElement. Have a look at the LegendElement example 3 in the help.

Another issue. There is a space on line 1 of your code, between the list and the index. It should read

legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT", "Legend")[0]
  • Thank you! this worked! for some reason, I now have a new issue! I am trying to update a different layer in the legend with a different style item, but I am receiving this error: ValueError: <geoprocessing Style Item object object at 0x5921880>
    – K_atarina
    Aug 14 '20 at 21:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.