Solved! Go to Solution.
Hi Y.Y.C,
You can do this using the ListFiles function. Ex:
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()
mxd = arcpy.mapping.MapDocument("current") layers = arcpy.mapping.ListLayers(mxd) for lyr in layers: if lyr.name == "something to change": lyr.name = "changed name" arcpy.RefreshTOC()
how do it for 4 mxd's in one folder?
Hi Y.Y.C,
You can do this using the ListFiles function. Ex:
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()
thank's- it's worked!! how do i mark your answer as the right one?
I changed your "discussion" to a "question" and marked Jake's answer as correct for you.
now,i have mxd's and each of them has 3 and more data frame. if I wan't to rename layer in a specific data frame with position in the TOC, for example in the first data frame, how to do it ?
also i have this question Insert layer file to specific data frame
can you see it please?
Branch multiple questions into individual ones and close the this thread by marking "helpful" or "like" to those that helped
I put mxd.save() at the end of the script, to ensure keep the changing.