ss_whaleman

How did I break RefreshActiveView() ?

Discussion created by ss_whaleman on Dec 7, 2011
Latest reply on Dec 8, 2011 by ss_whaleman
Yesterday, the code below worked fine.  I could select a country from a pulldown list and the location map dataframe would zoom to the country selected.  Then I tried several things including MakeFeatureLayer_management, but removed those attempts.  Now the RefreshActiveView() no longer refreshes the dataframe.  I have to click the refresh button to have the map zoom to the country.  I have tried rebooting and going back to earlier versions that worked.  It seems I broke the RefreshActiveView() method??

import arcpy
arcpy.AddMessage("BEGIN")
country_selected = arcpy.sys.argv[1] #country name as String
arcpy.AddMessage(country_selected + "...")
arcpy.env.workspace = r"D:\0_areamap_group"
mxd = arcpy.mapping.MapDocument("CURRENT")
arcpy.AddMessage("=============")

for df in arcpy.mapping.ListDataFrames(mxd):
    arcpy.AddMessage(df.name)
    if df.name == "locationmap":
        arcpy.AddMessage("found: " + df.name)
        for lyr in arcpy.mapping.ListLayers(mxd,"",df):
            if lyr.name == "world_countries":
                arcpy.AddMessage("found: " + lyr.name)
                expression = ""'"NAME"'" = '"+country_selected+"'"
                arcpy.AddMessage(expression)
                arcpy.SelectLayerByAttribute_management(lyr,"NEW_SELECTION",expression)
                df.extent = lyr.getSelectedExtent()
                df.scale = df.scale * 1.2
                mxd.activeView = 'PAGE_LAYOUT'    ##tried commenting this line out - no difference
                arcpy.RefreshActiveView()
                arcpy.SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION",expression)

Outcomes