export single page from data driven pages

273
1
10-14-2011 11:59 AM
JeffBaker2
New Contributor III
I am trying to create a python script that will allow export of just one page from a series of data driven pages but not having much luck.  More specifically, I have 187 data driven pages; I want to export only page 25 to .pdf.

I can run a python script to export all pages, and that works great, but after making minor edits to the data that show on only page 25, I only need to export page 25--not the entire series.

Can anyone provide a script to export just the one page?

-Jeff
Tags (2)
0 Kudos
1 Reply
AndrewChapkowski
Esri Regular Contributor
The data driven pages object has a property called currentPageID. This will allow you to you just print one page out of multiple pages for the data driven page series.  You can find more information here: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00s300000030000000

Here is an example:
import arcpy
from arcpy import mapping
from arcpy import env
import os
mxdPath = arcpy.GetParameterAsText(0)  # ex: r"c:\temp\ddpMap.mxd"
pageNum = arcpy.GetParameter(1)  # ex: 25
mxd = mapping.MapDocument(mxdPath)
ddp = mxd.dataDrivenPages
ddp.currentPageID = int(pageNum) # here you would pass 25;  casting to int() just to be safe
mapping.ExportToPDF(mxd, r"C:\test\mappage_" + str(pageNum) + ".pdf")
del mxd
del ddp


If you want to use the data driven page object to export maps, you can also do that as well. 
#.... other logic
#
ddp = mxd.dataDrivenPages
ddp.currentPageID = int(pageNum)
ddp.exportToPDF(r"c:\temp\mypage.pdf",page_range_type="CURRENT",multiple_files="PDF_SINGLE_FILE")
#... other code
#


Let me know how this works out.  Hope it helps!

Enjoy