BookmarkMapSeries

Summary

The BookmarkMapSeries object provides access to properties and methods for managing a bookmark map series.

Discussion

An existing bookmark map series can be referenced using the mapSeries property on a Layout object or using the createBookmarkMapSeries method. You pass in a MapFrame object and, optionally, a list of Bookmark objects you want to use to create 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.

Note:

ArcGIS Pro supports two types of map series: spatial and bookmark. The MapSeries class represents spatial map series. The mapSeries property on the Layout object will return a MapSeries object if a spatial map series is enabled, a BookmarkMapSeries object, or a NoneType value if a map series is not present.

The BookmarkMapSeries class can be used to access the individual pages in a map series for customization. For example, if a text element's string information needs to be formatted using custom logic, the map series can be referenced and arcpy.mp can handle the custom text element string requirements as each page is being processed as the script controls how to iterate through the pages. Another example is exporting a map series to an output format other than PDF, such as PNG. See the second code sample below that demonstrates how to loop through each page in a map series and export to a .png file.

The pages in a map series can be exported to PDF using the exportToPDF method . When you export 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. The output PDF can be appended or inserted into other PDFs using the PDFDocument class. See the PDFDocument help topic for more information and code samples.

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

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

bms.currentPageNumber = bms.getPageNumberFromName('Fenway')
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

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

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

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})
ParameterExplanationData 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.

  • ALLAll pages are exported.
  • CURRENTThe active or current page is exported.
  • RANGEOnly pages listed in the page_range_string parameter are exported.
  • SELECTEDDoes not apply to bookmark map series.
    Note:

    This option can only be used for a spatial map series in which index features can be selected. If it is used with a bookmark map series, all pages will be exported.

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

  • PDF_MULTIPLE_FILES_PAGE_NAMEExport each map series page to an individual file and append the page name to the file name. For example, Output.PDF will become Output_LakeErie.PDF
  • PDF_MULTIPLE_FILES_PAGE_NUMBERExport each map series page to an individual file and append the page number to the file name. For example, Output.PDF will become Output_1.PDF
  • PDF_SINGLE_FILEExport into a multipage, single file 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.

  • BESTAn output image quality resample ratio of 1
  • BETTERAn output image quality resample ratio of 2
  • NORMALAn output image quality resample ratio of 3
  • FASTERAn output image quality resample ratio of 4
  • FASTESTAn output image quality resample ratio of 5

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

  • ADAPTIVEAutomatically selects the best compression type for each image on the page. JPEG will be used for large images with many unique colors. DEFLATE will be used for all other images.
  • JPEGA lossy data compression.
  • JPEG2000Offers higher quality compression with smaller file size than JPEG. This compression is lossless if jpeg_compression_quality is set to 100.
  • DEFLATEA lossless data compression.
  • LZWLempel-Ziv-Welch, a lossless data compression.
  • NONECompression is not applied.
  • RLERun-length encoded compression.

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

  • LAYERS_ONLYExport PDF layers only.
  • LAYERS_AND_ATTRIBUTESExport PDF layers and feature attributes.
  • NONENo setting is applied.

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

getDefinition (cim_version)
ParameterExplanationData Type
cim_version

A string that represents the major version of the CIM that will be used.

  • V2The 2.x version of the CIM will be used.
  • V3The 3.x version of the CIM will be used.
String
Return Value
Data TypeExplanation
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)
ParameterExplanationData 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)
ParameterExplanationData 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

BookmarkMapSeries example 1

The following script checks for the presence of a bookmark map series and exports two of its pages to PDF based on bookmark names.

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.currentPageNumber = bms.getPageNumberFromName("Lake Superior") 
    bms.exportToPDF(os.path.join(relpath, 'Output', 'Ex1_LakeSuperior.pdf'),
                                'CURRENT', resolution=300)
    bms.currentPageNumber = bms.getPageNumberFromName("Lake Huron") 
    bms.exportToPDF(os.path.join(relpath, 'Output', 'Ex1_LakeHuron.pdf'),
                                'CURRENT', resolution=300)
print("Finished")
BookmarkMapSeries example 2

The following script exports each page of a map series to individual .png files and uses the page name of the index feature 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
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("Exporting {0}".format(bkmkName))  
      lyt.exportToPNG(os.path.join(relpath,'Output', f'Ex2_{bkmkName}.png'))
print("Finished")
BookmarkMapSeries example 3

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 set the map frame extent before creating a bookmark. 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 spatial 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
bms.exportToPDF(os.path.join(relpath, 'Output', 'Ex3_NewBMS.pdf'))                                        
os.startfile(os.path.join(relpath, 'Output', 'Ex3_NewBMS.pdf'))
BookmarkMapSeries example 4

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.

p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('Layout_BMS')[0]
bms = lyt.mapSeries
if isinstance(bms, arcpy._mp.BookmarkMapSeries):
  if bms.enabled:
    m = bms.mapFrame.map
    m_cim = m.getDefinition('V3')
    sortList = sorted(m_cim.bookmarks, key=lambda Bookmark: Bookmark.name)
    m_cim.bookmarks = sortList
    m.setDefinition(m_cim)
    bms.refresh()
    bms.exportToPDF(r'C:\temp\Ex4_Sorted.pdf')
os.startfile(r'C:\temp\Ex4_Sorted.pdf')
print("Finished")
BookmarkMapSeries example 5

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:
      print(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
      sms.exportToPDF(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))

#Export bookmark map series
bms_lyt = p.listLayouts('Layout_BMS')[0]
bms = bms_lyt.mapSeries
if ((type(bms).__name__ == 'BookmarkMapSeries')): 
  if bms.enabled:
    bms.exportToPDF(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))

#Combine PDFs and remove temporary files
comboPDF = arcpy.mp.PDFDocumentCreate(os.path.join(relpath, 'Output',
                                                   'Ex4_Combo.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_sms.pdf'))
comboPDF.appendPages(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
os.remove(os.path.join(relpath, 'Output', 'Temp_bms.pdf'))
comboPDF.saveAndClose()
os.startfile(os.path.join(relpath, 'Output','Ex4_Combo.pdf'))
print('Finished')