Skip to content

Instantly share code, notes, and snippets.

@amarinelli
Created November 13, 2014 19:46
Show Gist options
  • Save amarinelli/d882056d04f98cf892ba to your computer and use it in GitHub Desktop.
Save amarinelli/d882056d04f98cf892ba to your computer and use it in GitHub Desktop.
Set style of legend items to user style and tests 'Override default patch' property. Mxd.save() seems like the key here.
import arcpy
mxd = arcpy.mapping.MapDocument("./Legend.mxd")
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Setup Legend
legend = arcpy.mapping.ListLayoutElements(mxd, "LEGEND_ELEMENT")[0]
styleItems = arcpy.mapping.ListStyleItems("USER_STYLE", "Legend Items")
for styleItem in styleItems:
if styleItem.itemName == "PATCH_Single":
legendStyle = styleItem
for lyr in legend.listLegendItemLayers():
legend.updateItem(lyr, legendStyle)
mxd.save()
print "done"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment