Renaming Multiple Layouts via arcpy

267
3
01-27-2021 10:58 AM
JamesWilcox1970
New Contributor II

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 = arcpy.mp.ArcGISProject("CURRENT")  # For tool use
aprx = arcpy.mp.ArcGISProject(r"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(lyt.name)  # print the name
    oldName = lyt.name  # write layout name to variable
    newName = oldName.replace("Test", "Best")  # replaces old text with new 
    print(newName)  # everything works through this line
    # lyt.name = 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
JoeBorgione
MVP Esteemed Contributor

If you google that error number (esri error 000732) you'll find https://support.esri.com/en/technical-article/000010149 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?

can't wait to retire....
JamesWilcox1970
New Contributor II

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. 🙂

 

Thanks!

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