Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 6 down vote accepted

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.

share|improve this answer
    
Great answer - Rename_management is documented here help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//… –  PolyGeo Mar 20 '12 at 0:29
    
Oh, that was easier than I thought, thanks :-) –  Andy Arismendi Mar 20 '12 at 3:31
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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