Summary
The BookmarkMapSeries object provides access to properties and methods for managing a bookmark map series.
Discussion
The arcpy.mp module supports two types of map series: spatial and bookmark. The mapSeries property on the Layout object will return a mapSeries object if a spatial map series is present, a BookmarkMapSeries object if a bookmark map series is present, or a NoneType value if a map series is not present or enabled. The BookmarkMapSeries class can be used to customize individual map series pages during export. One example is with facing pages where even pages are shifted differently than odd pages to accommodate for binding space.
A new bookmark map series can be created with the createBookmarkMapSeries method by passing in MapFrame object and, optionally, a list of Bookmark objects used to use to create each page of the bookmark map series. If you don't pass in a list of bookmarks, the bookmarks from the Map object associated with the MapFrame object will be used by default. The bookmarks property represents the list of bookmarks in the map series. The list of bookmarks can be modified in a variety of ways and set back to the bookmark map series to control the order of pages that are presented in the application or during export.
Similar to the application, the map series can be exported to JPEG, PDF, PNG and TIFF file formats using the export method. These formats can also be further configured using the MapSeriesExportOptions object if non-default values are needed. When exporting a map series, all the dynamic elements associated with the map series are supported. For example, dynamic text elements—such as page name, page number, bookmark name, and more—will automatically update. If map surrounds such as legends, table frames, and chart frames are set up to use the map series constraint, those elements will also dynamically update.
Note:
A map series export may be limited to the formats listed above and can be further configured using MapSeriesExportOptions, but that doesn't mean you can't simulate map series export to a different format. The procedure is to update the layout with the current map series page and export the layout instead of the map series. The second code example below demonstrates how to do this.
The getDefinition and setDefinition methods provide access to CIM properties not exposed to the BookmarkMapSeries object. For more information and code samples, see the Python CIM access help topic.
Properties
Property | Explanation | Data Type |
bookmarks (Read and Write) | The list of bookmarks that will be used in the bookmark map series. Note:If you modify a bookmark list by setting a new list of bookmarks, you will need to call the refresh method so the bookmark map series pages update in the application. | List |
currentBookmark (Read Only) | Returns the current bookmark displayed in the map series. | Bookmark |
currentPageNumber (Read and Write) | The current page number that corresponds to the bookmark page displayed in the map series. This is how you set the appropriate bookmark page. If you are unsure of the page number, you can get the page number based on the bookmark name using the getPageNumberFromName method. Here is an example of how to set the currentPageNumber property using the bookmark name value.
| Long |
enabled (Read and Write) | Specifies whether the map series is enabled. Tip:Confirm that this property is set to True before changing the map series properties. | Boolean |
mapFrame (Read and Write) | The MapFrame object associated with the map series. If you change the map frame to something different, the original bookmarks remain and you should also use the refresh method. | MapFrame |
pageCount (Read Only) | The total page count for a layout that has map series enabled. This corresponds to the number of total bookmarks. | Long |
Method Overview
Method | Explanation |
export (export_format, {mapseries_export_options}, {display_options}) |
The export method exports a BookmarkMapSeries using a specified export_format and optionally different mapseries_export_options or display_options. |
exportToPDF (out_pdf, {page_range_type}, {page_range_string}, {multiple_files}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {output_as_image}, {embed_color_profile}, {pdf_accessibility}, {show_export_count}, {keep_layout_background}, {convert_markers}, {simulate_overprint}) | Exports a specified set of pages to a Portable Document Format (PDF) file for a layout that has map series enabled. Legacy:This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method. |
getDefinition (cim_version) | Returns a bookmark map series' CIM definition. |
getPageNumberFromName (page_name) | Returns the page number that corresponds to the name of the currently displayed bookmark map series page. |
refresh () | Refreshes an existing bookmark map series. |
setDefinition (definition_object) | Sets a bookmark map series' CIM definition. |
Methods
export (export_format, {mapseries_export_options}, {display_options})
Parameter | Explanation | Data Type |
export_format | The supported export_format objects are JPEGFormat, PDFFormat, PNGFormat, and TIFFFormat. | Object |
mapseries_export_options | The MapSeriesExportOptions object is only needed if there are changes to its default property values. | Object |
display_options | The DisplayOptions object that includes changes to the default antialiasing property values. | Object |
Refer to the MapSeriesExportOptions and DisplayOptions help topics to learn more details and get code samples.
exportToPDF (out_pdf, {page_range_type}, {page_range_string}, {multiple_files}, {resolution}, {image_quality}, {compress_vector_graphics}, {image_compression}, {embed_fonts}, {layers_attributes}, {georef_info}, {jpeg_compression_quality}, {clip_to_elements}, {output_as_image}, {embed_color_profile}, {pdf_accessibility}, {show_export_count}, {keep_layout_background}, {convert_markers}, {simulate_overprint})
Parameter | Explanation | Data Type |
out_pdf | A string that represents the path and file name of the output export file. | String |
page_range_type | The string value that designates how the pages will be printed.
(The default value is ALL) | String |
page_range_string | A string that identifies the pages to be exported if the RANGE option in the page_range_type parameter is used (for example, 1, 3, 5-12). If any other page_range_type value is used, the page_range_string value will be ignored. | String |
multiple_files | A string that controls how the output PDF file is created. By default, all pages are exported into a single, multipage document.
(The default value is PDF_SINGLE_FILE) | String |
resolution | An integer that defines the resolution of the export file in dots per inch (dpi). (The default value is 96) | Integer |
image_quality | A string that defines output image quality.
(The default value is BEST) | String |
compress_vector_graphics | A Boolean that controls the compression of vector and text portions of the output file. Image compression is defined separately. (The default value is True) | Boolean |
image_compression | A string that defines the compression scheme used to compress image or raster data in the output file.
(The default value is ADAPTIVE) | String |
embed_fonts | A Boolean that controls the embedding of fonts in an export file. Font embedding allows text and character markers to be displayed correctly when the document is viewed on a computer that does not have the necessary fonts installed. (The default value is True) | Boolean |
layers_attributes | A string that controls the inclusion of PDF layers and PDF object data (attributes) in the export file.
(The default value is LAYERS_ONLY) | String |
georef_info | A Boolean that enables the export of coordinate system information for each map frame into the output PDF file. (The default value is True) | Boolean |
jpeg_compression_quality | A number that controls the compression quality value when image_compression is set to ADAPTIVE or JPEG. The valid range is 1 through 100. A jpeg_compression_quality of 100 provides the best quality images but creates large export files. The recommended range is 70 through 90. (The default value is 80) | Integer |
clip_to_elements | If set to True, the layout is clipped to the smallest bounding box that includes all layout elements. (The default value is False) | Boolean |
output_as_image | If set to True, vector content can be saved as an image. Selecting this option for maps or layouts that contain vector layers with a high density of vertices can reduce the output file size. When exporting to PDF and this option is set to True, you cannot view PDF layers in the output. (The default value is False) | Boolean |
embed_color_profile | If set to True, color profile information is embedded in the image's metadata. (The default value is True) | Boolean |
pdf_accessibility | Output a tagged PDF file where text can be read by screen readers or other assistive technology. A tagged PDF file can include alt text—a text description of a graphic element that a screen reader uses to describe the element—for map frames, pictures, and chart frames. Alt text is added in the Element Pane for each element.
(The default value is False) | Boolean |
show_export_count | If set to True, you will see the status of each page being exported displayed in the Python shell. (The default value is False) | Boolean |
keep_layout_background | If set to True, the white background will be included in the export. (The default value is True) | Boolean |
convert_markers | A Boolean that controls the conversion of character-based marker symbols to polygons. This allows the symbols to appear correctly if the symbol font is not available or cannot be embedded. However, setting this parameter to True disables font embedding for all character-based marker symbols, which can result in a change in their appearance. (The default value is False) | Boolean |
simulate_overprint | Sometimes called soft proofing, simulating overprinting shows a representation of how overlapping areas of ink will appear when printed on a page. You set up overprinting on symbol layers. (The default value is False) | Boolean |
PDF files are designed to be consistently viewable and printable across various platforms. They are commonly used for distributing documents on the web and are a standard interchange format for content delivery. PDF files are editable in many graphics applications and retain annotation, labeling, and attribute data for map layers. PDF exports support embedding of fonts and can display symbology correctly even if the user does not have Esri fonts installed.
Legacy:
This method is superseded by export at ArcGIS Pro 3.4 and only remains for use in legacy scripts. All enhancements and future development will only occur on the export method.
getDefinition (cim_version)
Parameter | Explanation | Data Type |
cim_version | A string that represents the major version of the CIM that will be used.
| String |
Data Type | Explanation |
Object | Returns the CIM definition for a BookmarkMapSeries. |
For more information about working with the CIM and samples, see Python CIM access.
getPageNumberFromName (page_name)
Parameter | Explanation | Data Type |
page_name | The name of the Bookmark based on the Name field that was used to set up the map series. | String |
Many of the map series properties and methods use a page number value rather than the literal names of the pages. The getPageNumberFromName method provides a mechanism to obtain a page number from a page name.
bms = layout.mapSeries
pageNumber = ms.getPageNumberFromName("HarborView")
bms.currentPageNumber = pageNumber
refresh ()
If changes are made to any of the bookmarks or their order is modified, use the refresh method to refresh the bookmark map series pages in the application.
setDefinition (definition_object)
Parameter | Explanation | Data Type |
definition_object | A modified CIM definition object originally retrieved using getDefinition. | Object |
For more information about working with the CIM and code samples, see Python CIM access.
Code sample
The following script checks for the presence of a bookmark map series and exports two of its pages to PDF based on bookmark names. Because it exports one PDF at a time, the MapSeriesExportOptions class is configured to export the CURRENT page. The PDFFormat object only needs to be created once because the filePath property is changed between exports.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_BMS')[0]
bms = lyt.mapSeries
#Create a new PDF format and change the resolution from its default value of 96
pdf = arcpy.mp.CreateExportFormat('PDF')
pdf.resolution = 300
#Modify map series export options to export only the current page
msOpt = arcpy.mp.CreateExportOptions('MAPSERIES')
msOpt.setExportPages('CURRENT')
if isinstance(bms, arcpy._mp.BookmarkMapSeries):
if bms.enabled:
bms.currentPageNumber = bms.getPageNumberFromName("Lake Superior")
pdf.filePath = os.path.join(relpath, 'Output', 'Ex1_LakeSuperior.pdf')
bms.export(pdf, msOpt)
bms.currentPageNumber = bms.getPageNumberFromName("Lake Huron")
pdf.filePath = os.path.join(relpath, 'Output', 'Ex1_LakeHuron.pdf')
bms.export(pdf, msOpt)
The following script exports each page of a map series to individual .bmp files and uses the bookmark name as part of the output file name.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_BMS')[0]
bms = lyt.mapSeries
#Create a new PNG format that uses only defaults
bmp = arcpy.mp.CreateExportFormat('BMP')
if ((type(bms).__name__ == 'BookmarkMapSeries')):
if bms.enabled:
for pageNum in range(1, bms.pageCount + 1): #All pages, zero based index
bms.currentPageNumber = pageNum
bkmkName = bms.currentBookmark.name
print(f"Exporting {bkmkName}")
bmp.filePath =os.path.join(relpath,'Output', f'Ex2_{bkmkName}.bmp')
lyt.export(bmp)
The following script creates a Map object, a Layout object and a MapFrame object. Next, it adds a layer file to the map and iterates through each feature to create a list of bookmarks using the feature geometry to set the bookmark extent. Next, it create a bookmark map series and uses Python CIM access to modify some CIM properties not exposed to the BookmarkMapSeries object. Examples are setting the starting page number and scale rounding. Finally, it exports the map series to a single PDF.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
#Function used to create a rectangle where the anchor point is lower left corner
def MakeRec_LL(llx, lly, w, h):
xyRecList = [[llx, lly], [llx, lly+h], [llx+w,lly+h], [llx+w,lly], [llx,lly]]
array = arcpy.Array([arcpy.Point(*coords) for coords in xyRecList])
rec = arcpy.Polygon(array)
return rec
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
#Create a new map, layout, and map frame
m = p.createMap('New Map', 'MAP')
lyt = p.createLayout(8.5, 11, 'INCH', 'New Layout')
mf = lyt.createMapFrame(MakeRec_LL(0.5,5.5,7.5,5), m, "New Map Frame")
#Add a layer file and zoom to each feature and create a bookmark and add to list
lyrFile = arcpy.mp.LayerFile(os.path.join(relpath, 'GreatLakes', 'GreatLakes.lyrx'))
lyr = m.addLayer(lyrFile)[0]
bkmkList = []
for row in arcpy.da.SearchCursor(lyr, ['SHAPE@', 'NAME']):
mf.camera.setExtent(row[0].extent)
mf.camera.scale = mf.camera.scale * 1.1 #add a slight buffer
bkmkList.append(mf.createBookmark(row[1]))
#Create and export a bookmark map series
bms = lyt.createBookmarkMapSeries(mf, bkmkList)
#Modify CIM properties
bms_cim = bms.getDefinition('V3')
bms_cim.startingPageNumber = 2
bms.scaleRounding = 10000
bms.setDefinition(bms_cim)
#Export to PDF
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Ex3_NewBMS.pdf'))
bms.export(pdf)
The following script sorts a map's bookmarks after referencing an existing bookmark map series. The refresh method must be called to confirm that the bookmark pages are reordered in the application.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
lyt = p.listLayouts('Layout_BMS')[0]
bms = lyt.mapSeries
if isinstance(bms, arcpy._mp.BookmarkMapSeries):
if bms.enabled:
bms_cim = bms.getDefinition('V3')
sortList = sorted(bms_cim.pages, key=lambda CIMBookmarkMapSeriesPage: CIMBookmarkMapSeriesPage.bookmarkName)
bms_cim.pages = sortList
bms.setDefinition(bms_cim)
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Ex4_Sorted.pdf'))
bms.export(pdf)
The following script exports all the pages from a spatial map series to a single PDF, exports all pages from a bookmark map series to another PDF, and combines the two resulting PDFs into a single, newly created PDF.
import arcpy, os, sys
relpath = os.path.dirname(sys.argv[0])
arcpy.env.overwriteOutput = True
p = arcpy.mp.ArcGISProject(os.path.join(relpath, 'GreatLakes', 'GreatLakes.aprx'))
#Export spatial map series
sms_lyt = p.listLayouts('Layout_MS')[0]
sms = sms_lyt.mapSeries
if ((type(sms).__name__ == 'MapSeries')):
if sms.enabled:
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
sms.export(pdf)
#Export bookmark map series
bms_lyt = p.listLayouts('Layout_BMS')[0]
bms = bms_lyt.mapSeries
if ((type(bms).__name__ == 'BookmarkMapSeries')):
if bms.enabled:
pdf = arcpy.mp.CreateExportFormat('PDF', os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
bms.export(pdf)
#Combine PDFs and remove temporary files
comboPDF = arcpy.mp.PDFDocumentCreate(os.path.join(relpath, 'Output', 'Ex5_Combo.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
comboPDF.saveAndClose()
os.remove(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))