Allow renaming of layouts and maps when importing layout file

206
6
4 weeks ago
Status: Open
Labels (1)
FourCornersMapping
New Contributor III

Allow user to rename Layout and Maps when importing a layout file (.pagx). Often I have multiple maps within a single layout, and both the Layout and Maps within are appended with a number after the name of the layout file (i.e. Layout Wildlife1, Main Map Wildlife1, Inset Map Wildlife1, etc.). I have to rename these every time I import a layout file, which is time-consuming. I would like the option to rename these items when importing the layout file.

Screen Shot 04-12-24 at 08.57 AM.PNG

 

Screen Shot 04-12-24 at 09.01 AM.PNG

Tags (3)
6 Comments
JeffBarrette

Hello @FourCornersMapping,

I can't speak to doing this in the User Interface but this might be automated using Python.

For example,

p = arcpy.mp.ArcGISProject('current')
newLyt = p.importDocument(r"C:\temp\Layout.pagx", True, True)
newLyt.name = "New Layout"

This technique only allows you to rename one object at a time.  In the above example, I'm using reuse existing maps = True so if the map already exists, it doesn't get recreated as a project item.

The importDocument function can also be used to import mapx and many other file types.

Jeff - arcpy.mp and Layout teams

Yarkaah

Great one @JeffBarrette . 

I think we could update this code a little bit to accommodate flexibility and error handling. In that way the revised code will be : 

def import_layout(project, filepath, new_name):
try:
p = arcpy.mp.ArcGISProject(project)
newLyt = p.importDocument(filepath, True, True)
newLyt.name = new_name
except Exception as e:
print(f"An error occurred: {e}")

import_layout('current', r"C:\temp\Layout.pagx", "New Layout")
Yarkaah

Hope that help.

 

Yaw Arkaah

FourCornersMapping

@Yarkaah @JeffBarrette Please point me to the help resources for the importDocument and import_layout methods (I found this but curious what else there is). I do NOT want to reuse existing maps, so I would also need to make "reuse existing maps" = FALSE and add to the script the ability to rename maps that will be created when the new layout is created. At the end of the day though, I don't want to use python to do this--my request is for the functionality to be included in the user interface. Thanks.

JeffBarrette

@FourCornersMapping the importDocument method can be found under the ArcGISProject help topic: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/arcgisproject-class.htm

This is not a replacement for your idea, it is a possible workaround for now. Python is great at automation. If you are not familiar with using Python for automation, I understand.

The logic will need to be extended further if you want to set {reuse_existing_maps=False} because the object returned is a layout (for import PAGX) so you would need to know how to find the additiona, newly added maps that are also imported and then rename them accordingly.  If there is a way to predict the names of the imported maps, then you could reference them and rename them using arcpy.mp.

Here is an introductory help topic: https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/introduction-to-arcpy-mp.htm

Jeff

m = p.listMaps('imported map name')[0]
m.name = "New Name"

 

FourCornersMapping

New maps in an imported .pagx file (Layout file) take the name of the maps in the Layout used to make the .pagx and append them with a number. So if there are two maps, i.e. Main Map and Inset Map, those are named Main Map1 and Inset Map1 in the new layout. This is what I got to work. 

 

p = arcpy.mp.ArcGISProject('current')
newLyt = p.importDocument(r"C:\temp\Layout.pagx", True, False)
newLyt.name = "New Layout"
m = p.listMaps('Main Map1')[0]
m.name = "Main Map New Name"
m = p.listMaps('Inset Map1')[0]
m.name = "Inset Map New Name"

 

If I fiddled long enough I'm sure I could figure out how to do this by wildcard, listing by order in the list, then renaming based on a variable (newname = "New Name").