Export Data Driven Pages to MXD with file name by Page Name

10277
11
Jump to solution
01-10-2012 02:23 PM
BrunoDeus
New Contributor III
I`m trying export multiple files created by DDP to ".mxd" once each page has the file name defined by the "page name" or by a "field name". Some what the ArcGis already does to export to ".pdf" whereas it exports single-page documents using the page name for the output file name.

I saw a script from Ideas webpage: Export Data Driven Pages to MXD which is almost perfect to me, but the file name came from Page number.

I`ve tried modify It considering all the information that I saw on another pages (Help, ArcGIS Ideas, Foruns), but it doesn`t works until now.
I would like that somebody can helps me. I've made a copy from the last version of script:

>>>import arcpy, os
... mxdPath = r"C:\...\Projeto_DataDrive.mxd" # The original path is too large
... mxd = arcpy.mapping.MapDocument(mxdPath)
... mxdDir = os.path.dirname(mxdPath)
... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
... pageName = mxd.dataDrivenPages.pageRow.COD_APRT #This line wasn't here in the original script. The FieldName who is indexing the DDP is COD_APRT
... mxd.dataDrivenPages.currentPageID = pageNum
... mxdName = os.path.join(mxdDir, "DDPMap" + str(pageName) + ".mxd")# I just modified str(pageNum) to str(pageName)
... mxd.saveACopy(mxdName)
... del mxd
...

I will appreciate any help.
Tags (2)
11 Replies
MichelleNing
New Contributor II
Hi Andrea,

I just figured out how to fix this same issue a couple weeks ago. You need to add an extra "\" to the end of your export location:

ddp.exportToPDF(r"O:\Missouri\MO18\Details\2013 Create from NISC GIS\TEST\\" + str(bookNum) + "_" + str(pageName) + ".pdf", "CURRENT")

Michelle
0 Kudos
MichelleNing
New Contributor II
THANK YOU!!! I knew it was a syntax error but I didn't know what or why.

Thanks again!


You're welcome! You need to add a extra backslash because '\' is a special character in python.  I'm just learning how to utilize python too.  This link might help clarify when you need to use it when you use special characters in your code: 

http://pythonweb.org/projects/webmodules/doc/0.5.3/html_multipage/lib/node48.html