import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
for lyr in arcpy.mapping.ListLayers(mxd):
if lyr.supports("DEFINITIONQUERY"):
lyr.definitionQuery = "INSERT_YOUR_DQ_HERE"
To insert formatted code:
If your definition query is the same for all specified layers:
layer_names = ["Layer A", "Layer B", "Layer E"] mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name in layer_names and lyr.supports("DEFINITIONQUERY"): lyr.definitionQuery = "INSERT_YOUR_DQ_HERE"
If you want different queries for the layers:
queries = { "Layer A": "Query for Layer A", "Layer B": "Query for Layer B", "Layer E": "Query for Layer E", } mxd = arcpy.mapping.MapDocument("CURRENT") for lyr in arcpy.mapping.ListLayers(mxd): if lyr.name in queries and lyr.supports("DEFINITIONQUERY"): lyr.definitionQuery = queries[lyr.name]
For example, maybe try the following:
For file geodatabase (gdb) or shapefile:lyr.definitionQuery = '"Docket"' + " = " + "'1254-2017'"or for personal gdblyr.definitionQuery = '[Docket]' + " = " + "'1254-2017'"
-Jeff
Can you explain to me with more details .... what should i replace in my python script to do what i want ? I do not understand Docket"' + " = " + "'1254-2017'" !!
Docket = field in the layers attribute file.
'1254-2017' = is a specific txt value.
Please also refer to JL's post... Great info
Membros conectados podem postar, seguir atualizações e mais. Novo aqui? Registre uma conta gratuita.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.