Skip to main content
edited tags; edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

Use Using ArcPy to rename MXD layers?

edited tags
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345
Tweeted twitter.com/#!/StackGIS/status/181932613336965120
Source Link
Andy Arismendi
  • 805
  • 1
  • 10
  • 22

Use ArcPy to rename MXD layers

I have a MXD with some layers that have parentheses in them. I'd like to rename them via script.

Is this a valid approach?

import re
map = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(map)
for layer in layers:
    if re.search("[()]", layer.name):
        newName = re.sub("[()]", "", layer.name)
        arcpy.Rename_management(layer, newName)

Rename_management is giving me an error:

Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000840: The value is not a Data Element.