I have a layer where I have symbolized the features on unique values. I have also grouped several features together. EX) Layer: Land Use; Value Field: Type of Land Use; Unique Values of different park types have been grouped together and there 'Label' changed to "Parks"; All other unique values left the same.
Using ArcPy 10.2, how can I print the "Label" (not the unique value itself) of the Unique Value categorization? I am looking for something where I can use arcpy.mappings?
enter image description here
3 Answers 3
Use classLabels
from the UniqueValuesSymbology
class
mxd = arcpy.mapping.MapDocument(path_to_your_mxd)
lyr = arcpy.mapping.ListLayers(m)[0]
print(lyr.symbology.classLabels)
Relevant documentation: http://resources.arcgis.com/en/help/main/10.2/index.html#/UniqueValuesSymbology/00s30000005s000000/
Is it possible to change the layer label, from arcpy, in a simple symbol layer?
I have this code, and want to change something in it, to do what i want. It only changes the layer name.
import arcpy
from arcpy import env
env.workspace = r"C:\temp\python"
for mxdFile in arcpy.ListFiles("*.mxd"):
mxdPath = env.workspace + "\\" + mxdFile
mxd = arcpy.mapping.MapDocument(mxdPath)
layers = arcpy.mapping.ListLayers(mxd)
for lyr in layers:
if lyr.name == "something to change":
lyr.name = "changed name"
arcpy.RefreshTOC()
I figured how to do what I needed up here. I just need to change it, the way I want one time, then save a .lyr from the correct information (it can also change symbology, and other stuff).
The script below, will apply the .lyr file to your layer in the TOC. You just must specify the name of the layer, like displayed in TOC.
It will do to all MXD files, in the same folder of the script.
import arcpy, os
from arcpy import env
env.workspace = os.curdir
for mxdFile in arcpy.ListFiles("*.mxd"):
mxdPath = env.workspace + "\\" + mxdFile
mxd = arcpy.mapping.MapDocument(mxdPath)
layers = arcpy.mapping.ListLayers(mxd)
for lyr in layers:
if lyr.name == "layer_name_in_TOC": #change here
print mxdPath
symbologyLayer = r"D:\LayerFile.lyr" #change here
arcpy.ApplySymbologyFromLayer_management (lyr, symbologyLayer)
arcpy.RefreshTOC()
mxd.save()
Explore related questions
See similar questions with these tags.