Select to view content in your preferred language

Data driven pages - exporting multiple PNG by page name

5851
2
06-13-2013 04:55 PM
RichardKeightley
Emerging Contributor
Hi,

It took me a long time of searching forums to work out how to export mutliple data driven pages to a format other than PDF, using the page name in the file name (instead of the page number).

My page names also included characters that file naming won't accept (e.g "/"), and I wanted to remove spaces.  I was exporting to PNG.

Here's the script if anyone else has the same problem.

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
  mxd.dataDrivenPages.currentPageID = pageNum
  pageName = mxd.dataDrivenPages.pageRow.Name
  pageName = pageName.replace("/", "_")
  pageName = pageName.replace(" ", "")
  arcpy.mapping.ExportToPNG(mxd, r"C:\temp\" + pageName + ".png")
del mxd
2 Replies
BertrandMARTINEZ
Deactivated User
Hello,

I have the same problem. I'm new in Python and would like to export one Data driven to Jpeg format with the page name instead of page number for name of the generated file.
I've tried the code above, with the change in red:

mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
pageName = mxd.dataDrivenPages.pageRow.N_Parcelle
arcpy.mapping.ExportToJPEG(mxd, r"C:\temp\" + pageName + ".jpeg")
del mxd

But the problem for me is the line 3:
"Parsing error <type 'exceptions.IndentationError'>: expected an indented block (line 3)"

Someone could help me, I'm sure i'm really near
thanks
+++
0 Kudos
JimCousins
MVP Regular Contributor
Python requires proper indentation
mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
 mxd.dataDrivenPages.currentPageID = pageNum
 pageName = mxd.dataDrivenPages.pageRow.N_Parcelle
 arcpy.mapping.ExportToJPEG(mxd, r"C:\temp\" + pageName + ".jpeg")
del mxd 
0 Kudos