Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Data Driven Pages: Python code to include page index in output file name?

$
0
0
I have used the DDP toolbar to set up DDP where 'Reach' is the index layer (as in river reach). Each of the 100 Reaches has an ID, stored in the attribute table. I want the output JPG name to be Reach ID plus _reachmap.jpg, concatenated. However, instead of Reach ID I am getting a number between 1 and 100. I have tried replacing pageNum with various other things but I get the same results or an error. How can I get DDP to 'see' the Reach ID instead of the generic 1 to 100?

Code:

import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
    mxd.dataDrivenPages.currentPageID = pageNum
    arcpy.mapping.ExportToJPEG(mxd, r"C:\output\\" + str(pageNum) + "_reachmap.jpg")
del mxd


Viewing all articles
Browse latest Browse all 2485

Trending Articles