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 : ERROR 000840: The value is not a Data Element.


1 Answer 1


This is because arcpy.Rename_management does not work on a map layer object - it works on objects on the disk.

Instead try:

layer.name = newName

layer.name is a read/write attribute of the arcpy.mapping.Layer class.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.