try: import arcpy, sys, traceback print "Working..." mxdPath = r"Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\WaterSampleSiteAutoMap22.mxd" mxd = arcpy.mapping.MapDocument(mxdPath) df = arcpy.mapping.ListDataFrames(mxd)[0] lyr = arcpy.mapping.ListLayers(mxd, "WaterSampleSiteMaster", df)[0] print lyr.dataSource theAttribute = "SiteID" #GetAListOfEachAttribute listOfAttributes = [] print "Start cursor" rows = arcpy.SearchCursor(lyr.dataSource) for row in rows: listOfAttributes.append(row.getValue(theAttribute)) for elm in arcpy.mapping.ListLayoutElements(mxd, "TEXT_ELEMENT"): if elm.name == 'gbglabeler': elm = elm break for item in listOfAttributes: GBGquery = '"SiteID" =' + '\''+ item + '\'' print "Working on: ",item print GBGquery lyr.definitionQuery = GBGquery elm.text = "Site: " + item outputjpg = "Z:\GISpublic\GerryG\WaterResources\WaterSampleSiteAutoMap\SiteMaps\\" + item + ".jpg" arcpy.RefreshActiveView() arcpy.mapping.ExportToJPEG (mxd, outputjpg) print "done" except arcpy.ExecuteError: msgs = arcpy.GetMessages(2) arcpy.AddError(msgs) #If the error is with the script, or with python, find error and report it to the screen... except: tb = sys.exc_info()[2] tbinfo = traceback.format_tb(tb)[0] pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1]) msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n" arcpy.AddError(pymsg) arcpy.AddError(msgs)
I too would like to be able to maintain the same extent for DDP. All that is needed is to add an additional option on the "Extent" tab which says "Keep current extent".
I found a simple way to achieve DDP where the extent of the maps remains exactly the same:
*If you don't have an ArcGIS Advanced Licence: