1

I work with several MXD files. In each map there a polygon layer with unique values:

enter image description here enter image description here enter image description here

I try to change in the table of contents the "a" into "land use" by using this code:

import arcpy,os,sys
from arcpy import env
env.workspace = r"G:\desktop\Project"
for mxdname in arcpy.ListFiles("*.mxd"):
 print mxdname 
 mxd = arcpy.mapping.MapDocument(r"G:\desktop\Project\\" + mxdname)
 df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0] 
 lyr = arcpy.mapping.ListLayers(mxd, "*")[0]
 if lyr.symbologyType == "UNIQUE_VALUES":
 vals = lyr.symbology.classLabels
 for v in vals:
 if v == "a":
 print lyr.name
 v = 'landUse'
 print v 
 mxd.save()
del mxd 

I just want to change the name in the table of content, and not change the attribute table value. When running this code i get this result and with no change in the maps:

>>> 
project.mxd
polygon
landUse
>>> 
asked Jul 18, 2016 at 13:00

1 Answer 1

3

To update the labels, you'll need to update them all at once by providing a list to lyr.symbology.classLabels.

if lyr.symbologyType == "UNIQUE_VALUES":
 vals = lyr.symbology.classLabels
 newLabels = []
 for v in vals:
 if v == "a":
 v = 'landUse'
 newLabels.append(v) # push each label into the list
 lyr.symbology.classLabels = newLabels # apply the new labels
mxd.save()
answered Jul 18, 2016 at 14:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.