change definition query on layers in mxd file

Discussion created by rbasaria on Mar 8, 2011
Latest reply on Mar 8, 2011 by rbasaria
Hi everyone. Ive done a bunch of searches, and have gotten much farther than I would have otherwise, but I am still getting stuck. I am trying to create a script that will change the definition query on a speicific layer in an MXD file. The script will then select by location, intersected with the new features from the layer that the definition query was changed for. Then these selected features will be copied to a new feature class or shapefile. Here is the code I have at this point. Thank you in advance for any help!!

import arcpy

mxd = arcpy.mapping.MapDocument("C:/Rafig_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/DataPrep.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):
    if lyr.name == "CountyCommission_TriCounty":
        layer.definitionQuery = "[DISTRICT] = '1' AND [COUNTY] = 'ORANGE'"