Data Driven Pages and python

04-05-2013 06:18 AM
New Contributor III
I am attempting to export a set of maps using python and data driven pages.  I have been successful in getting the code to work but I am struggling with the file naming of the exported JPEG's.  I need to the file names to coincide with a field in the attribute table.  Basically I am making a set of parcel maps, and need the file name to be the parcel number (PARCEL_NO).  Here is the code I am using.  I am a novice when it comes to this stuff so please be patient.  Thanks in advance!

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.mapping.ExportToJPEG(mxd, r"P:\Township Maps\Bloomingdale\JPEG" + str(pagename) + ".jpeg")
del mxd
0 Kudos
5 Replies
Occasional Contributor III
I dont think you have 'pagename' defined anywhere.

I think you want to getPageIDFromName

I do something that's probably unconventional. I have an element in my MXD which is a dynamic text from DDP (the Page name), and then i define that element as a parameter in my model. I can then reference that parameter later when I go to name and export the PDF.

Also, in the future, you may have better luck in the Map Automation forum.
0 Kudos
Esri Contributor
Hi Ryan,

Are you getting a specifc error with your code?  What is the current code actually doing when ran?

0 Kudos
New Contributor
I'm running a similar script where I defined:

ddp = mxd.dataDrivenPages

then ran something similar to this (changed for your code):

arcpy.mapping.ExportToJPEG(mxd, r"P:\Township Maps\Bloomingdale\JPEG" + ddp.pageRow.pagename + ".jpeg")

This is assuming that "pagename" is the field in the attribute table that you are trying to use to label. I'm pretty new to python myself though so there may be an easier way.
0 Kudos
New Contributor III
Hi Ryan,
try adding this to your script
# Get the value from the field called tilename, e.g. ab1234. (This should be a string field)
  name = row.getValue("TILE_NAME")

  # Set Output location
  outputlocation = arcpy.GetParameterAsText(0)
  # Concatenate into whole path name
  outputName = outputlocation + "\\" + name + "_ArcMap" + ".tif"

I've just extracted this from a longer bit of code I posted here

0 Kudos
New Contributor III
This is a duplicate thread to this one in the Geoprocessing forum.
0 Kudos