<?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 Re: Change definition query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14809#M1139</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is done by modifying the Layer object's definitionQuery property. There are several examples to get you started in the help here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000" rel="nofollow" target="_blank"&gt;Desktop 10.1 Help: (arcpy.mapping)&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] # first data frame lyrs = arcpy.mapping.ListLayers(mxd, "" , df) fixLayers = ["Test1 polygon","Test2 polygon"] newParcel = 5 for lyr in lyrs: &amp;nbsp; if lyr.name in fixLayers: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = "parcel_no = {0}".format(newParcel) arcpy.RefreshActiveView() del mxd # release the object (the map will not be deleted)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 22 Apr 2013 11:44:02 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2013-04-22T11:44:02Z</dc:date>
    <item>
      <title>Change definition query</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14807#M1137</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have three feature classes that have multiple features in each layer. Each feature class has a field called parcel_no. I turn different parcels on by a definition query on each layer such as parcel_no = 1. This will show all three layer for parcel 1. I would like to run a script that will change the definition query for all three layers, say from parcel_no = 1 to parcel_no = 5. New to python and need to be pointed in the right direction.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 21 Apr 2013 03:28:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14807#M1137</guid>
      <dc:creator>MarkPaulson</dc:creator>
      <dc:date>2013-04-21T03:28:19Z</dc:date>
    </item>
    <item>
      <title>Re: Change definition query</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14808#M1138</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi Mark,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would recommend using a Python Add-In &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//014p00000028000000" rel="nofollow noopener noreferrer" target="_blank"&gt;Combo Box&lt;/A&gt;&lt;SPAN&gt;.&amp;nbsp; You can select the query from the drop down and apply it to the desired layers.&amp;nbsp; Here is an example of the code to use for the combo box:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
import pythonaddins

class ComboBoxClass1(object):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Implementation for Query_addin.combobox (ComboBox)"""
&amp;nbsp;&amp;nbsp;&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.items = ['"parcel_no" = 1', '"parcel_no" = 2', '"parcel_no" = 3', '"parcel_no" = 4', '"parcel_no" = 5']
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.editable = False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.enabled = True
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.dropdownWidth = 'WWWWWWWWWW'
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.width = 'WWWWWWWWWW'
&amp;nbsp;&amp;nbsp;&amp;nbsp; def onSelChange(self, selection):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.mxd = arcpy.mapping.MapDocument("CURRENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(self.mxd):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name.lower() == "parcels1":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name.lower() == "parcels2":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.name.lower() == "parcels3":
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = selection
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshTOC()
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14808#M1138</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-10T20:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Change definition query</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14809#M1139</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;This is done by modifying the Layer object's definitionQuery property. There are several examples to get you started in the help here:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A class="jive-link-external-small" href="http://resources.arcgis.com/en/help/main/10.1/index.html#//00s300000008000000" rel="nofollow" target="_blank"&gt;Desktop 10.1 Help: (arcpy.mapping)&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy mxd = arcpy.mapping.MapDocument(r"C:\Project\Project.mxd") df = arcpy.mapping.ListDataFrames(mxd)[0] # first data frame lyrs = arcpy.mapping.ListLayers(mxd, "" , df) fixLayers = ["Test1 polygon","Test2 polygon"] newParcel = 5 for lyr in lyrs: &amp;nbsp; if lyr.name in fixLayers: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.definitionQuery = "parcel_no = {0}".format(newParcel) arcpy.RefreshActiveView() del mxd # release the object (the map will not be deleted)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 22 Apr 2013 11:44:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14809#M1139</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-04-22T11:44:02Z</dc:date>
    </item>
    <item>
      <title>Re: Change definition query</title>
      <link>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14810#M1140</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the direction. Ended up setting 15 bookmarks (1-15) and used a for loop to set the definition query for each parcel. Many thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 24 Apr 2013 02:19:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/change-definition-query/m-p/14810#M1140</guid>
      <dc:creator>MarkPaulson</dc:creator>
      <dc:date>2013-04-24T02:19:39Z</dc:date>
    </item>
  </channel>
</rss>

