I am attempting to use python and arcpy to automate the creation of some standardized maps I need to export for feature classes from various projects. I have a set of points and I need to export a single map for each point in the feature class, showing only one point at a time.
I can iterate through the features and export the maps just fine. However, the maps that come out are not panned to the right area, most of the time they are totally off.
I am using lyr.definitionQuery to hide all the features but one, then I need to pan my data frame so that it is centered on that feature, then export the map, and repeat for all the features in the feature class. The best I could find to recenter the data frame was the df.panToExtent function. Which works fine when I run it from the python window in ArcMap but doesn't seem to keep up when it runs inside the loop. Any help is MUCH appreciated!
Here is my loop:
while isoPosition < isoCount: #iterate through the feature class query = "[Type] = 'Isolate' AND " + "[FieldID] = " + "'" + FieldIDs[isoPosition] + "'" #center on feature df.panToExtent(lyr.getSelectedExtent()) #Refresh the view to load new image tiles arcpy.RefreshActiveView() #Set the layers definition query equal the query text lyr.definitionQuery = query #String for a unique file name for each map, corresponding to the current Field ID in FieldIDs filename = FieldIDs[isoPosition] #Export the map document: arcpy.mapping.ExportToPNG(mxd,filename) #Move forward in the FieldIDs array, so that next time through we export the next map isoPosition += 1