Changing the Definition Query for multiple features

4150
2
07-01-2015 12:57 PM
MikeFarrell
New Contributor

Hi

I have an mxd that contains the same shape file numerous times so that I can portray it in different ways on the map,

I would like to be able to change the definition query for these shape files with out having to go to each file and change each one at a time

Is there some type of a tool or script that can change the same file's definition query with in a mxd

Tags (1)
0 Kudos
2 Replies
IanMurray
Frequent Contributor

This can be done with Python, you could have a tool that lists all the layers in a mxd, then changes the defintion query value for each of them.

ArcGIS Help 10.1

0 Kudos
IanMurray
Frequent Contributor

Within the map document, this is what you would need in the python window.  If you have multiple dataframes, you would need a bit more code.

import arcpy
mxd = arcpy.mapping.MapDocument("Current")
layers = arcpy.mapping.ListLayers(mxd)
for layer in layers:
    if layer.supports(definitionQuery)
         layer.definitionQuery = """FieldName = 'Value'"""