Solved! Go to Solution.
Is there a way to change the 'label' of the layerfile? The script above, changes the layer name. But i want to change the layer name. I'm refering to the name is written right after the symbol, in the TOC.
since you posted this question https://community.esri.com/message/673130-re-how-can-i-change-the-layer-label-in-toc-with-py you may want to delete your comment/question above. If geonet doesn't allow you to, I might be able to do it for you.
i'm just trying to get as many options as possible.
I figured how to do it. I just need to change it, the way i want one time, than 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()