andra.bobbitt

Data Driven Pages - PICTURE_ELEMENT - SourceImage changes

Discussion created by andra.bobbitt on May 3, 2011
Latest reply on May 4, 2011 by jbarrette-esristaff
Using a previous script posted on this forum, I've gotten the data-driven layouts to print out pdfs with an image (PICTURE_ELEMENT) that changes based on an attribute of the index layer storing the image name (using sourceImage).  However, the ArcMap displayed pages do not update the image source and continues to use the first image. 

Is the PICTURE_ELEMENT supposed to change on the layouts for each data driven page as well as the output to pdfs?

Here is the sort-of working code:

import arcpy
mxd = arcpy.mapping.MapDocument(r"G:\NEPacific\Data-types\maps\andra-datadriven-test-map.mxd")
imagePath = "G:\\NEPacific\Data-types\Vent-locations\Axial\images\\"
for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
mxd.dataDrivenPages.currentPageID = pageNum
imageName = mxd.dataDrivenPages.pageRow.getValue("image4map")
for elm in arcpy.mapping.ListLayoutElements(mxd,"PICTURE_ELEMENT"):
  if elm.name == "photo1":
   nextImage = (str(imagePath) + str(imageName))
   elm.sourceImage = nextImage
print "Exporting Page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))
arcpy.mapping.ExportToPDF(mxd, r"G:\NEPacific\Data-types\maps\andra-datadriven-test-map.mxd" + str(pageNum) + ".pdf")
del mxd

Outcomes