1

I am an experienced Arc user but new to python. I can not figure out where my syntax is wrong. I'm trying to use data driven pages to export to jpeg where the name of the file is the page name. It works fine through the usual export to pdf in File, Export, Pages dialog so I know that the data driven pages are set up correctly. The first line references the field name in the attribute table of the layer file that I have set to be the page name. The script works if I use the page number.

I'm using ArcGIS 10.2.2 for Desktop with a basic licence.

arcpy.mapping.ExportToJPEG(mxd, r"C:\Temp\Linn\Linn_KCH" + str(pageNum) + ".jpg")

This is the script I'm trying to run now.

field_name = "Page_Name"

mxd = arcpy.mapping.MapDocument("CURRENT")
for i in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = i
row = mxd.dataDrivenPages.pageRow

pageName = mxd.dataDrivenPages.pageRow.Name

print row.getValue(field_name)
arcpy.mapping.ExportToJPEG(mxd, r"C:\Temp\Linn\Linn_KCH" + "." + row.getValue(field_name) + str(pageName) +".jpg") 
del mxd

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.