Renaming Multiple Layouts via arcpy

01-27-2021 10:58 AM
New Contributor III

I am trying to create a tool that will let me rename multiple layouts one after the other, ideally by replacing just a portion of the name. For example, "City_north_map_projects" and "City_north_map_sites" would become "City_south_map_projects" and "City_south_map_sites". So far, I have tried a number of things. This is the code for the latest attempt:


import arcpy

# Set Variables
# aprx ="CURRENT")  # For tool use
aprx ="PATH TO THE APRX/APRX.aprx") # Development use. Has 3 layouts: Test_layout, Test_layout1, Test_layout2

for lyt in aprx.listLayouts():  # for each layout in the project
    print(  # print the name
    oldName =  # write layout name to variable
    newName = oldName.replace("Test", "Best")  # replaces old text with new 
    print(newName)  # everything works through this line
    # = newName  # Doesn't actually rename the layout? Commented out to try arcpy.Rename
    arcpy.Rename_management(oldName,newName)  # Fails here with error 000732



I am sure there is something simple, but I am *very* new at Python.

Tags (2)
0 Kudos
3 Replies
MVP Esteemed Contributor

If you google that error number (esri error 000732) you'll find which just describes what's going on.  Looking at the arcpy.Rename_management() method help, it appears to work for actual data sets rather than a layout object.

I'm not sure what would work for renaming a layout, but I've got a little bit of time before I'm off to zoom-meeting land so I'll keep digging.  Perhaps someone else knows?

That should just about do it....
New Contributor III

I suspected that was the case. I had seen an instance where someone was using Rename() to change folder names, and though it might work with layouts. :)



0 Kudos
New Contributor
  aprx ="filepath.aprx")
  layout = aprx.listLayouts()[0]
   if == "Whatever your layout name is": = "Name it this"
   del aprx
0 Kudos