jallpress

Definition Query Not Applied to all Layers in Dataframes

Discussion created by jallpress on Oct 28, 2011
Latest reply on Oct 28, 2011 by jallpress
I am trying to apply a definition query to multiple layers in multiple dataframes.  My code works for the dataframe named 'US' but for the other dataframes the layers are not updated before the export.  All of the print statements I have included appear to reflect that the code is working however, the exported map does not show the definition queries having been applied. 

Any ideas as to what I am missing?

Thanks

            for df in arcpy.mapping.ListDataFrames(NationMapMxd):
                if df.name == "US":
                    for layer in arcpy.mapping.ListLayers(NationMapMxd,"*",df):
                        if layer.name == "st2000al83cl":
                            print "Ignoring state layer"
                        else:
                            DefQuery = '"GP_%s" = %s'%(Variable, layer.name[2])
                            print "Definition query is " + DefQuery
                            layer.definitionQuery = DefQuery
                            arcpy.RefreshActiveView()
                else:
                    print "moving onto " + df.name
                    for layer in arcpy.mapping.ListLayers(NationMapMxd,"*",df):
                        print "dataframe is " + df.name
                        if layer.name == "st2000al83cl":
                            print "Ignoring state layer"
                        else:
                            print "layer is called " + layer.name
                            DefQuery = '"GP_%s" = %s'%(Variable, layer.name[2])
                            #DefQuery2 = ' AND "ST" = '
                            #DefQuery3 = "'%s'"%(df.name)
                            #FinDefQuery = DefQuery + DefQuery2 + DefQuery3
                            #"GP_abodalc" = 1 AND "ST" = 'AK'
                            print "Final Query is " + DefQuery
                            layer.definitionQuery = DefQuery
                            arcpy.RefreshActiveView()

            arcpy.RefreshTOC      
            ExportMaps(Variable, NationMapMxd)

Outcomes