I have a layout exist where i need to update the text element of the specific maps extent areas generated map series page name ?
I am use the layer name to generate grid and then i have generate the map series using that grid layer.
Now i want to populate the selected areas PageName on my layouts text element after filtering the feature layer for specific area.
below is the code that i have used.
import arcpy,os arcpy.env.overwriteOutput = True # Project object aprx = arcpy.mp.ArcGISProject("current") # Map objects mainMap = aprx.listMaps("Main Map")[0] overviewMap = aprx.listMaps("Overview Map")[0] # Layer objects countriesLayer = mainMap.listLayers("zone")[0] # Layout object lyt = aprx.listLayouts()[0] field_name = "PageName" l_cim = countriesLayer.getDefinition('V3') #Get layer's CIM / Layer URI lURI = l_cim.uRI #Needed to specific the index layer lyt_cim = lyt.getDefinition('V3') #Get Layout's CIM definition #Create CIM Spatial Map Series Object and populate its properties ms = arcpy.cim.CreateCIMObjectFromClassName('CIMSpatialMapSeries', 'V3') ms.enabled = True ms.mapFrameName = map_frame_name ms.startingPageNumber = 1 ms.currentPageID = 2 ms.indexLayerURI = lURI #Index layer URI from Layer's CIM ms.nameField = field_name ms.sortField = field_name ms.sortAscending = True ms.scaleRounding = 50 ms.extentOptions = "BestFit" ms.marginType = "Percent" ms.margin = 10 lyt_cim.mapSeries = ms #Set new map series to layout lyt.setDefinition(lyt_cim) #Set the Layout's CIM definition #Force a refresh of the layout and its associated panes lyt_cim = lyt.getDefinition('V3') lyt.setDefinition(lyt_cim) # Map Frame objects mainMapFrame = lyt.listElements('MAPFRAME_ELEMENT',"Main Map Frame")[0] overviewMapFrame = lyt.listElements('MAPFRAME_ELEMENT',"Overview Map Frame")[0] finalPDF = r"C:\LPA\PDFs\LayoutFromCursor.pdf" pdfDoc = arcpy.mp.PDFDocumentCreate(finalPDF) countriesSortedByNameList = sorted([row[0] for row in arcpy.da.SearchCursor( countriesLayer,"NAME")]) for pageCount,countryName in enumerate(countriesSortedByNameList[:10]): countriesLayer.definitionQuery = "NAME = '{0}'".format(countryName) selCountryExtent = mainMapFrame.getLayerExtent(countriesLayer) mainMapFrame.camera.setExtent(selCountryExtent) mainMapFrame.camera.scale = mainMapFrame.camera.scale * 1.05 countriesLayer.definitionQuery = "" print(countryName) # Title text object titleText = lyt.listElements("TEXT_ELEMENT","Page Name")[0] #### Display PageName of the Map Series #### #titleText.text = "" # Export PDF for this country's page lyt.exportToPDF(r"C:\LPA\PDFs\test{0}.pdf".format(pageCount)) pdfDoc.appendPages(r"C:\LPA\PDFs\test{0}.pdf".format(pageCount)) # Save and close PDF and open in Adobe Acrobat Reader pdfDoc.saveAndClose() del pdfDoc # Delete project object del aprx
Hello,
I see in your code you are creating a MapSeries object via the CIM but I don't see how you are using the map series object to drive extents. You are exporting a layout, not a map series. If a MapSeries object is in place you can use the pageRow.FieldName (used to define the map series pages) syntax to return the page name. Here is a very simplified example.
p = arcpy.mp.ArcGISProject('current')
lyt = p.listLayouts('*MS')[0]
ms = lyt.mapSeries
for pageNum in range(1, ms.pageCount + 1):
ms.currentPageNumber = pageNum
print(ms.pageRow.Name)