Data Driven Pages and python

2092
5
04-05-2013 06:18 AM
RyanMiller
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
ZacharyHart
Regular Contributor
I dont think you have 'pagename' defined anywhere.

I think you want to getPageIDFromName

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s300000030000000

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
MatthewPayne
Esri Contributor
Hi Ryan,

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

Matt
0 Kudos
ChrisWitt1
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
DanielHall_Ballester
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
http://forums.arcgis.com/threads/89608-python-script-zoom-to-each-county-in-a-state-shp-and-export-a...

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