3

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
PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Sep 27, 2012 at 17:50
0

1 Answer 1

2

I have solved my own problem. It seems that I just had the order of the commands messed up. I needed to set the layer definition query BEFORE using panToExtent function, not after.

answered Oct 2, 2012 at 17:45

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.