ppadegimas

setting data frame extent does not work in select cases

Discussion created by ppadegimas on Aug 15, 2012
Latest reply on Aug 15, 2012 by mdenil
I have a python script that effectively creates a series of maps by iterating over a set of geodatabases and replaces data sources in a template file.  Part of the the script loops over the layers in the sole data frame and sets the extent of the data frame and the spatial reference based on those of a layer within.  After the loop I change the scale by using a multiplier, set the data frame spatial reference, and refresh my active view.  Example of code is below:

        # define data frame
        df = arcpy.mapping.ListDataFrames(mxd, "Layers")[0]
        # set the utm spatial reference and zoom to layer
        sr = ""
        for lyr in arcpy.mapping.ListLayers(mxd):
            if lyr.name == "neat_contour_55":
                print lyr.name
                df.extent = lyr.getSelectedExtent()
                sr = arcpy.Describe(lyr).spatialReference
        df.scale = df.scale * 1.25
        df.spatialReference = sr
        arcpy.RefreshActiveView()

I have used this portion of script before to change the data frame extent and it has worked successfully.  Recently I have run into an issue where about 5 percent of the maps I am attempting to create do not change extent.  The only thing that has changes in my system is that I have since upgraded to 10.1.  In the results, the spatial reference does change, and the data is properly replaced, but the extent upon which the map is focused remains where the data in the template resided.  For example, my template is based on Atlanta and I am mapping part of Seattle, and while the data is there, the map remains centered on Atlanta.  There is no error that occurs, the extent seems to be correct based on what I had printed during execution of my script, but the final map and associated pdf are incorrect and simply display the background states layer in the area of Atlanta.

If anyone has had any similar issues, or can offer any advice, it would be much appreciated.

Thank you!

Paul P.

Outcomes