Select to view content in your preferred language

Exporting Data Driven Pages to EPS using Python

4193
12
10-20-2010 02:18 PM
TomFlahive
Occasional Contributor
Currently in ArcGIS 10 you can export all of the pages of a data driven pages map book to .pdf format.  Unfortunately, you cannot do the same thing when exporting to .eps format or any of the other export formats (not sure why).  Is there a way to us python to iterate through the individual pages of a data driven pages map book so that each page can be exported to .eps one by one?
0 Kudos
12 Replies
TomFlahive
Occasional Contributor
I found the answer.  It can be done and there is a code example in the help files (although the export format in the example is .png):

http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/DataDrivenPages/00s300000030000000/
0 Kudos
AngelaRemer
New Contributor
My reason for responding to this post is two fold:

1: Is to show the sample code to export to EPS that is working.
2: Since the upgrade to ArcGIS 10 Service Pack 1, the script now produces negative images.  I am still a beginner in the Python scripting world....any tips to how to fix this:


# Import system modules
import sys, arcpy

# Define current mxd
mxd = arcpy.mapping.MapDocument ("CURRENT")

# Local variables inputed by user
sheetname = sys.argv[1]
folder = sys.argv[2]

# Process: export EPS data driven pages
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
   mxd.dataDrivenPages.currentPageID = pageNum
   arcpy.AddMessage ("exporting sheet " + str(pageNum))
#add leading zeros
   if pageNum < 10:
      arcpy.mapping.ExportToEPS(mxd, str(folder) + "\\" + str(sheetname) + "_00" + str(pageNum) + ".eps")
   elif pageNum <100:
      arcpy.mapping.ExportToEPS(mxd, str(folder) + "\\" + str(sheetname) + "_0" + str(pageNum) + ".eps")
   else:
      arcpy.mapping.ExportToEPS(mxd, str(folder) + "\\" + str(sheetname) + "_" + str(pageNum) + ".eps")

Thanks.
0 Kudos
ShannonPorter
Occasional Contributor
We too are having trouble with python now producing negative eps images.  Have you resolved the issue?  It does appear to be a problem with Service Pack 1.  This kind of kills us being able to use the new scripting abilities.
0 Kudos
JeffBarrette
Esri Regular Contributor
This is a known issue and is being addressed.

Jeff
0 Kudos
PaulBrandt
Regular Contributor
I too was having the negative image problem at sp1. I discovered a workaround, if you pass a value of 1 for the jpeg_compression_quality parameter, it comes out as a positive image. My suspicion is that ESRI has this parameter mapped incorrectly at sp1 when they ship it to arcobjects. All of the other values I tried for the jpeg_compression_quality parameter resulted in a negative image.
0 Kudos
KayAnderson
Emerging Contributor
When you say pass a value of 1 for the JPEG compression quality parameter what exactly are you referring to?  We have not had any success with this yet.

Thanks!
Kay
0 Kudos
PatrickGronli
Deactivated User
@Kay:  He's referring to the option to set jpeg quality when scripting the export in Python.  My colleagues have had success running this one, with no negative image results:

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.mapping.ExportToEPS(mxd, r"C:\Temp\Map_Page" + str(pageNum) + ".eps", image_quality="BETTER", image_compression="DEFLATE", picture_symbol="RASTERIZE_PICTURE", convert_markers=True, embed_fonts=False, jpeg_compression_quality=1)
del mxd

However, when I run the ExportToEPS code with the "jpeg_compression_quality=1" option, I get the following error message: 

Runtime error <type 'exceptions.TypeError'>: ExportToEPS() got an unexpected keyword argument 'jpeg_compression_quality'

My colleagues are running Adobe Acrobat Standard 8 and I am running Adobe Acrobat Standard 9, so that may be where the disparity lies.  I modified the script to be built into a tool with output variables, and omitted the "jpeg_compression_quality" option and it works very well for me (no negative images):

# Import ArcPy site-package and os modules
#
import arcpy
import os
# Set the output workspace
#
outWorkspace = arcpy.GetParameterAsText(0)
# Set the output map name
#
mapname = arcpy.GetParameterAsText(1)
# Tell ArcMap to use the current MXD
#
mxd = arcpy.mapping.MapDocument("CURRENT")
# Execute dataDrivenPages
#
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  arcpy.mapping.ExportToEPS(mxd, outWorkspace + str(mapname) + str(pageNum) + ".eps", image_quality="BETTER", image_compression="DEFLATE", picture_symbol="RASTERIZE_PICTURE", convert_markers=True)
del mxd

Search on "ExportToEPS" in ArcGIS 10 Help to get the breakdown of the syntax and all output options.  You'll notice that the "jpeg_compression_quality" option is not mentioned in there...
0 Kudos
KayAnderson
Emerging Contributor
Thank you very much, we will give this a try.  We are using Adobe 9 too so I appreciate you including that.
0 Kudos
TomGiles
Deactivated User
Hi all,

Was hoping someone could help me out.

This all works for me, except that the pages don't change - it keeps exporting the same page over and over again.

Any ideas? I would think "mxd.dataDrivenPages.currentPageID = pageNum" would change the page (ie feature driving the page), so each successive "routeNum = mxd.dataDrivenPages.pageRow.routeID" would get the value for routeNum from the new feature driving the datadrivenpages (the next 'page').

Cheers,
Tom
0 Kudos