Data Driven Page Export ArcPRO to Image

07-10-2018 09:32 AM
New Contributor II

The key issue to me seems to be:


Is not working in arcpro in respect to a row object from a layout mapseries, this worked  just fine in ArcGIS (10.3)


I am trying to automate the export of a data driven page into .png in arcpro.  The issue I am running into working out how to automate the naming of the output .png's.

The naming pattern I want to use is

theOutput = outDir + '\\' + theBase + '_'+str(theNameValue) + ".png"


outDir is an output directory which is passed into the job as a parameter.

theBase is the base file name of the arcpro project and is defined thus

theBase = os.path.splitext(os.path.basename(aprx.filePath))[0]

The issue is arising in setting theNameValue. 

I want to use the value of mapsSeries.pageNameField for the current page the script is iterating through. 

A sample script is attached and requires the following parameters.

outDir = arcpy.GetParameterAsText(0) # Create or use an output directory variable
outRes = arcpy.GetParameterAsText(1) # Resolution of PNG in dpi.
theLayout = arcpy.GetParameterAsText(2) #The layout we want to push out DDPs on.

Now on my test data I happen to have set the map series name field to be a field named: Name (the use case is bridges, but that's not really relevant...) but it is successfully used in line 23


Now according to the help on map series line 20 on the snippet below, theRow should be returning a row object.   

Checking what theRow is via line24 returns:  [0, 'Aughnacrew Bridge Culvert', 'BR01', ' ']

on the test data I was using this is expected.  According to the help on row objects this should have a method

getValue (field_name)

that Gets the field value....

However when I try to use it like in line 26:


It will cause the code to fail like the image below and as far as I can tell this should work.

Can anyone help me understand why this is not working?  

I have managed to get this script to  sort of work by calling


But this does not strike me as good form.

I am using ArcPRO 2.2.0

for lyt in aprx.listLayouts(theLayout):
    if == theLayout:
        #we check we are hitting on our desired 
        if  lyt.mapSeries is not None:
            ms = lyt.mapSeries
            idxLyer = ms.indexLayer
            idxLyerName =
            if ms.enabled:
                arcpy.AddMessage("\n\tMap Doc is data driven page.\n\tAll good to proceed")
                #get the name field.
                theNameField =
                test = ms.pageNameField
                #get the number of pages to use for push out
                for pageNum in range(1,ms.pageCount + 1):
                    #make the page the current page number..
                    ms.currentPageNumber = pageNum
                    theRow = ms.pageRow
                    fields = arcpy.ListFields(idxLyerName)
                    arcpy.AddMessage(theRow)    #seeing what row contains
                    arcpy.AddMessage(theRow[1]) #access row by index
                    #arcpy.AddMessage(theRow.getValue(theNameField))    #This causing fail
                    arcpy.AddMessage(dir(theRow))   #find out what methods and attributes theRow has.
                    arcpy.AddMessage(theRow.__getattribute__(theNameField)) #This works?
                    arcpy.AddMessage("where is this going wrong?")
                    theOutput = outDir + '\\' + theBase + '_'+str(theRow.__getattribute__(theNameField)) + ".png"

geoprocessing fail due to line:arcpy.AddMessage(theRow.getValue(theNameField))

0 Kudos
3 Replies
MVP Emeritus
msg = theRow.getValue(theNameField)

python format strings automatically convert whatever to a string representation.  You can control whether you want str or repr to be used as in the example below

a = np.arange(10)

'[0 1 2 3 4 5 6 7 8 9]'

"{!s:}".format(a)      # str is used by default
'[0 1 2 3 4 5 6 7 8 9]'

"{!r:}".format(a)      # repr can be used if the object has one
'array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])'
0 Kudos
New Contributor II

Hi Dan Patterson

This is not really the key issue, getting a string returned is the desired outcome.  The issue to me seems to be a


Is not working in arcpro. 

The same line in a script that worked just fine in ArcGIS (10.3) is below.  All I was attempting was to upgrade a script for use in ArcPRO.  The bit wrecking my head is according to the documentation it "should work". 

As far as I can tell the row object returned from the layout mapseries for the current page we are iterating through our pages does not have access to getValue (field_name) method but according to the ArcPY documentation for Row that method is alive and well...

#Get details of map document that called this script to run...
mxd = arcpy.mapping.MapDocument("CURRENT")

# get the name field
theNameField =

for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    #get the value of theNameField  for the current row of the index layer
    theRow = mxd.dataDrivenPages.pageRow
    theNameValue = theRow.getValue(theNameField )‍‍‍‍‍‍‍‍‍‍‍‍

However thanks for the reply, this will be a handy tip in debugging when one is not sure what you are really getting back.


0 Kudos
Occasional Contributor


I try also to make png file for my mapseries. I saw your script and its seems great. I dont know if you find a solution.

If yes,would it possible please to share it again.

Sorry for my poor english.



0 Kudos