I work with arcmap 10.2.2 and I have 10 mxd's in one folder. I try to sort the legend items with a python code by moving the legend items up\down and i want that the layers in the TOC stay as is. I saw this question "Resequencing Legend Items using ArcPy?" but didn't get my answer from it. I try this code but it doesn't work:
import arcpy,os,sys,string import arcpy.mapping from arcpy import env 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.moveItem(lyr) print 'move' mxd.save() del mxd
أكثر...
import arcpy,os,sys,string import arcpy.mapping from arcpy import env 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.moveItem(lyr) print 'move' mxd.save() del mxd
أكثر...