<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic change definition query on layers in mxd file in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-definition-query-on-layers-in-mxd-file/m-p/30467#M2396</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

mxd = arcpy.mapping.MapDocument("C:/Rafig_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/DataPrep.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "CountyCommission_TriCounty":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.definitionQuery = "[DISTRICT] = '1' AND [COUNTY] = 'ORANGE'"

arcpy.SelectLayerByLocation_management("BusRoutes_Ridership","INTERSECT","CountyCommission_TriCounty","","NEW_SELECTION")

arcpy.CopyFeatures_management("BusRoutes_Ridership","C:/Rafig_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/Or_Com1.shp")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 08 Mar 2011 18:10:56 GMT</pubDate>
    <dc:creator>RafiqBasaria</dc:creator>
    <dc:date>2011-03-08T18:10:56Z</dc:date>
    <item>
      <title>change definition query on layers in mxd file</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query-on-layers-in-mxd-file/m-p/30467#M2396</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;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!!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy

mxd = arcpy.mapping.MapDocument("C:/Rafig_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/DataPrep.mxd")

for lyr in arcpy.mapping.ListLayers(mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name == "CountyCommission_TriCounty":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; layer.definitionQuery = "[DISTRICT] = '1' AND [COUNTY] = 'ORANGE'"

arcpy.SelectLayerByLocation_management("BusRoutes_Ridership","INTERSECT","CountyCommission_TriCounty","","NEW_SELECTION")

arcpy.CopyFeatures_management("BusRoutes_Ridership","C:/Rafig_GIS/PYTHONTESTING/2011/2011_CountyComm/Data/Orange/Or_Com1.shp")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2011 18:10:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query-on-layers-in-mxd-file/m-p/30467#M2396</guid>
      <dc:creator>RafiqBasaria</dc:creator>
      <dc:date>2011-03-08T18:10:56Z</dc:date>
    </item>
    <item>
      <title>Re: change definition query on layers in mxd file</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query-on-layers-in-mxd-file/m-p/30468#M2397</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Additionally, how can I make it so that the layer having the definition query changed, the definition query itself, and the output are all user defined parameters? (I will be changing the definition query mutliple times, and I will be querying 2 different layers separately. Each selection will have its own output, for a total of something like 30 layers at the end.) Thank you.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 08 Mar 2011 18:16:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query-on-layers-in-mxd-file/m-p/30468#M2397</guid>
      <dc:creator>RafiqBasaria</dc:creator>
      <dc:date>2011-03-08T18:16:24Z</dc:date>
    </item>
  </channel>
</rss>

