1

Using ArcPro, I need to create a ton of maps for the foreseeable future, and each product I create needs to be in its own folder. I'm trying to make a Python script that will do the following to an existing map series:

  1. Grab the page name of the map page.
  2. Create a folder (named using the page name) at destination.
  3. Export page layout to that folder.
  4. Repeat for each page layout in the project.

However, I can't get it to grab the actual page name, so the rest of the process is breaking.

I have a map series that is mapping individual points stored in a feature class. I have joined a table with other important data, including a file name for each feature. The map series was created referencing those file names, so each layout page is named after its correct intended file name.

So I've googled everything I can and tried a bunch of different variable names, but this is the one that seems the most promising.

import arcpy
import os

aprx = arcpy.mp.ArcGISProject("CURRENT")
layout = aprx.listLayouts()[0] *# Get the first layout in the project*
ms = layout.mapSeries *# Get the map series object*
output_path = r"...destination..." *# Set the output path*

for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum *# Set the current page number*
pageName = ms.pageNameField.name *# Set the page name using page name field*
arcpy.CreateFolder_management("...destination...", pageName)

(I haven't included any code for exporting the layout, until I figure out how to even create the folders) So this code does something. I've watched it iterate through the list of page layouts. But it just creates a folder called NameTextData.File_Name over and over again, overwriting it each time. I feel like I'm heading in the right direction, because it is technically pulling info about the page name.

NameTextData is the name of the tabe I joined to the feature class, and File_Name is the attribute column that contains the file names / page names I want.

So rather than pulling the actual value for the File_Name, it's just showing the path that the name is being pulled from.

If anyone knows the correct variable name I should be using, or if there's something else that would work so much better, I'd really appreciate it. Also if you have any input on the rest of it, like how to correctly export to the folder that was just created, that would be great. Thanks!

1 Answer 1

1

You are close, arcpy does not explicitly give you access to the current MapSeries page name, but you can get there using pythons built-in getattr() function.

If you adjust your code a bit, you get the page name like this:

ms = layout.pageSeries
name_field = ms.pageNameField.name
for page in range(1, ms.pageCount):
    ms.currentPageNumber = page
    page_name = getattr(ms.pageRow, name_field) #this is your page name.

Using the page name you can start create the subfolders.

credit

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.