Hi. I've got a Python script for exporting a MapSeries to PNG in a Project that contains multiple MapSeries. My can't seem to figure out how to specify the MapSeries to export. I've included the script below. I've been tweaking the layout_number values. It does change the MapSeries output, but I'm not sure how to determine the layout number? Any suggestions? Or is there a way to specify by "layout_name"? Thanks
_______________________________________________________
import arcpy, os, sys, pathlib
output_folder = pathlib.Path(os.path.dirname(sys.argv[0])) / "Output"
output_png_fname_pattern = "{this_row.Index}_{this_row.Index}.png"
layout_number = 0
output_folder = pathlib.Path(output_folder)
os.makedirs(output_folder, exist_ok=True)
p = arcpy.mp.ArcGISProject("CURRENT")
l = p.listLayouts()[layout_number]if not (l.mapSeries is None):
ms = l.mapSeries
if ms.enabled:
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
this_row = ms.pageRow
output_fname = output_png_fname_pattern.format(this_row=this_row)
l.exportToPNG(output_folder / output_fname,
transparent_background=True,
clip_to_elements=True,
resolution=300)
Solved! Go to Solution.
I'm not sure how the index numbers for the layouts get assigned -- they seem kind of arbitrary to me. Possibly it depends on the order that in which the layouts were created?
The layouts do have a name attribute, which you could use to construct a dictionary:
layouts = p.listLayouts()
l_dict = {l.name: l for l in layouts if not l.mapSeries is None}
Alternately, if you know the name, you can use it as a wildcard when you call p.listLayouts():
l = p.listLayouts("yournamehere")[0]
Note that the [0] is required even when searching for an exact name with only a single match among your layouts, because listLayouts() returns that match inside a list object.
I'm not sure how the index numbers for the layouts get assigned -- they seem kind of arbitrary to me. Possibly it depends on the order that in which the layouts were created?
The layouts do have a name attribute, which you could use to construct a dictionary:
layouts = p.listLayouts()
l_dict = {l.name: l for l in layouts if not l.mapSeries is None}
Alternately, if you know the name, you can use it as a wildcard when you call p.listLayouts():
l = p.listLayouts("yournamehere")[0]
Note that the [0] is required even when searching for an exact name with only a single match among your layouts, because listLayouts() returns that match inside a list object.
thanks, Andrew. the wildcard solution is exactly what I was looking for. Cheers