AnsweredAssumed Answered

PICURE_ELEMENT with new sourceImage floats to new position on ExportToPDF

Question asked by knapp on Feb 24, 2012
Latest reply on Mar 1, 2012 by knapp
Hi All -

Am using some code found in the Python forum to replace the sourceImage of a PICTURE_ELEMENT based on the current name field using Data Driven Pages.
It works fine, except that the image floats away a bit further each page, even when I'm resetting the elementPosition.
This behavior does NOT happen when I comment out the ExportToPDF function. Anyone see this before? Here's the code:

import arcpy mxd = arcpy.mapping.MapDocument(r"Y:\MAPS\MAPBOOKS\Driving_Direction\Driving_Directions_Update_2012.mxd") elm = arcpy.mapping.ListLayoutElements(mxd, "PICTURE_ELEMENT", "FacilityPhoto")[0] elmX = elm.elementPositionX; elmY = elm.elementPositionY elmHeight = elm.elementHeight; elmWidth = elm.elementWidth     #for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1): for pageNum in range(1, 4):  mxd.dataDrivenPages.currentPageID = pageNum  imageName = mxd.dataDrivenPages.pageRow.getValue("SITENAME")  elm.sourceImage = ("Z:\\FACILITY_SITES\\Facility_Photos\\" + imageName.replace(':','') + ".jpg")  elm.elementPositionX = 2.5  elm.elementPositionY = 0.5  elm.elementHeight = 2.5  print "Exporting Page {0} of {1}".format(str(mxd.dataDrivenPages.currentPageID), str(mxd.dataDrivenPages.pageCount))  print "X:" + str(elm.elementPositionX) + " Y:" + str(elm.elementPositionY)  print "Height:" + str(elm.elementHeight) + " Width:" + str(elm.elementWidth)   # Export to individual PDF files  arcpy.mapping.ExportToPDF (mxd, "Y:\\MAPS\\MAPBOOKS\\Driving_Direction\\MAP_BOOK\\" + str(pageNum) + ".pdf")  #mxd.dataDrivenPages.exportToPDF ("Y:\\MAPS\MAPBOOKS\\Driving_Direction\\MAP_BOOK\\Driving_Directions", page_range_string=" + pageNum + ", multiple_files="PDF_MULTIPLE_FILES_PAGE_NAME", page_range_type="CURRENT",image_quality="BETTER") del mxd


Thanks.

Mike Knapp

Outcomes