1

Running ArcGIS Pro 2.2, I have a layer in ~20 maps that needs it's name changed. I pulled this code together from a bunch of snippets, and have done my best to make sure it's updated appropriately, but I've hit a point where it runs without an error, but there are no changes afterwards.

What am I missing here?

import arcpy
aprx = arcpy.mp.ArcGISProject(r"C:\GIS_Local\Working.aprx")
for m in aprx.listMaps():
  layers = m.listLayers()
  for lyr in layers:
    if lyr.name == "old name":
      lyr.name = "new name"

There's a similar Q&A from a couple years ago - Use ArcPy to rename MXD layers, but I haven't been able to get the code there to update to Python 3.0 correctly, so I pulled this from the samples on the ESRI help and this GeoNet post

2

You need to save your project to persist the changes that you have made to layer names in its maps.

Add this at the end with no indent:

aprx.save()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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