Hi everyone
I'm trying to rename the layers in an open ArcMap session. When I run the script below it renames the layers but then they are removed. If I close the mxd without saving it and reopen it the layers are there and are renamed. If you rename one layer with the following code it works and the layer is not removed:
arcpy.mapping.ListLayers(mxd)[0].name = ???New Layer Name???
Am I doing something wrong here or is this somekind of bug.
I appreciate all the help I can get
BR
Johan Sandell
CODE:
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd,"", df):
if lyr.isFeatureLayer:
tempName = lyr.name.replace('_',' ')
lyr.name = tempName
arcpy.RefreshTOC()
del mxd