<?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: ArcGIS Pro - Modifying Layer Definition query via ArcPY in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1147595#M63869</link>
    <description>&lt;P&gt;I was able to get this method to work as well. For context: I am running script tools&amp;nbsp; that allow users to set and clear definition queries for multiple layers. When setting, they select a value from a drop down list and run the script which creates and applies the query with their selected value to all the relevant layers. When clearing, they simply run the script tool and all definition queries are cleared from the relevant layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the syntax I used for clearing queries. I am into an issue where it gave an error if the layer didn't already have a DQ on it, so it couldn't overwrite it. So I check for existing DQs first, if there is one, I overwrite it, if there isn't one, I create and apply one.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
    m = aprx.activeMap
    lyrs = m.listLayers()
    
    for lyr in lyrs:
        if lyr.name in ('TEST_PT', 'TEST_LINE', 'TEST_POLY'):
            cim_layer = lyr.getDefinition('V2')
            
            if cim_layer.featureTable.definitionFilterChoices:
                cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = None
                cim_layer.featureTable.definitionExpression = None
                
            else:
                cim_layer.featureTable.definitionExpression = None
            
            lyr.setDefinition(cim_layer)&lt;/LI-CODE&gt;&lt;P&gt;Doing it this way allowed me to create, apply, and clear definition queries without creating a massive list of deactivated queries for each layer. Hope this helps others.&lt;/P&gt;</description>
    <pubDate>Thu, 24 Feb 2022 16:48:29 GMT</pubDate>
    <dc:creator>MikeLachance1</dc:creator>
    <dc:date>2022-02-24T16:48:29Z</dc:date>
    <item>
      <title>ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258922#M19904</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Let's say I need to add a new statement to an existing Def query to all layers in a group which would like like something like this:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;aprx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mp&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ArcGISProject&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"CURRENT"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
m &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; aprx&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listMaps&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Map"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lyr &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; m&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;supports &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"longname"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 parent &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;longName&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'\\'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
 
 &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; parent &lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;&lt;SPAN class="number token"&gt;0&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"Group"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
 &lt;SPAN class="keyword token"&gt;print&lt;/SPAN&gt; &lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;longName&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;supports&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"DEFINITIONQUERY"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
   oldDefQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionQuery
   lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; None
   newDefQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; oldDefQuery &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;" CODE = 0"&lt;/SPAN&gt; 
   lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; newDefQuery‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What happens after running the script is that the old definition query becomes inactive and&amp;nbsp;the newly created query is added and becomes active. However they both remain the same query name and seem to clash with each other so that no feature pass through the query (don't mind the fieldnames):&lt;/P&gt;&lt;P&gt;&lt;IMG class="image-1 jive-image" src="https://community.esri.com/legacyfs/online/461462_pastedImage_1.png" /&gt;&lt;/P&gt;&lt;P&gt;There seem to be no detailed explanation on the&amp;nbsp;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;definitionQuery property at&amp;nbsp;&lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Layer—ArcPy | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #4c4c4c; background-color: #ffffff; font-weight: 300;"&gt;So the questions are:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;How to achieve this to work properly:&lt;UL&gt;&lt;LI&gt;Modify the existing one? - This used to work in ArcMAP&lt;/LI&gt;&lt;LI&gt;Remove the initial query completely and place a new modified query?&lt;/LI&gt;&lt;/UL&gt;&lt;/LI&gt;&lt;LI&gt;Is there any documentation on how to control the functions in the definition query tab on layer properties via Arcpy??&amp;nbsp;&lt;IMG class="image-2 jive-image" src="https://community.esri.com/legacyfs/online/461463_pastedImage_3.png" /&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks heaps!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:44:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258922#M19904</guid>
      <dc:creator>janrykr1</dc:creator>
      <dc:date>2021-12-11T12:44:33Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258923#M19905</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Did you ever manage to solve this?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 24 Feb 2020 06:58:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258923#M19905</guid>
      <dc:creator>FPCWAGIS_Admin</dc:creator>
      <dc:date>2020-02-24T06:58:26Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258924#M19906</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since I am not sure of the OP's code indentations, I will focus on once you have a reference to a layer:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;sql &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# Additional WHERE clause to append to existing&lt;/SPAN&gt;

lyr_cim &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;getDefinition&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;'V2'&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
cim_ft &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; lyr_cim&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;featureTable
defExpName &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cim_ft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionExpressionName
defExpIdx &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; next&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;
    i &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt;
    i&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt;n &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt;
    enumerate&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;cim_ft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionFilterChoices&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
    &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; n&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;name &lt;SPAN class="operator token"&gt;==&lt;/SPAN&gt; defExpName
&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
cim_ft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionExpression &lt;SPAN class="operator token"&gt;+=&lt;/SPAN&gt; sql
cim_ft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionFilterChoices&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;defExpIdx&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; cim_ft&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionExpression
lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;setDefinition&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lyr_cim&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 12:44:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258924#M19906</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T12:44:36Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258925#M19907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;No, haven't solved this entirely.&amp;nbsp; The easiest workaround was to go back to ArcMap.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Feb 2020 02:49:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258925#M19907</guid>
      <dc:creator>janrykr1</dc:creator>
      <dc:date>2020-02-25T02:49:58Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258926#M19908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Since Esri exposed the CIM model to ArcPy starting with Pro 2.4 (or was it 2.3), it opened the doors to doing a lot more within Pro that wasn't available strictly through ArcPy in the past with Pro.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Feb 2020 18:45:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/258926#M19908</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-02-25T18:45:32Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1005714#M59172</link>
      <description>&lt;P&gt;This seemed to work. It changed the def query without the duplication. Note that you have to change &lt;EM&gt;two&lt;/EM&gt; CIM properties to get this to change without duplication AND to make the new query the 'active' query.&amp;nbsp;&lt;/P&gt;&lt;P&gt;# sorry for bad indents; I don't know how to format this here&lt;/P&gt;&lt;P&gt;# batch change (all maps in project) definition query for a specified layer&lt;BR /&gt;# optional param - specify which map you want to target, default is that it does all of them&lt;/P&gt;&lt;P&gt;def batch_change_definition_query(layer_name, definition_query, my_map = None):&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;BR /&gt;for map in aprx.listMaps(my_map):&lt;BR /&gt;for layer in map.listLayers():&lt;BR /&gt;if layer.name == layer_name:&lt;BR /&gt;cim_layer = layer.getDefinition('V2')&lt;BR /&gt;cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = definition_query&lt;BR /&gt;cim_layer.featureTable.definitionExpression = definition_query&lt;BR /&gt;layer.setDefinition(cim_layer)&lt;/P&gt;</description>
      <pubDate>Tue, 01 Dec 2020 17:10:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1005714#M59172</guid>
      <dc:creator>danashney</dc:creator>
      <dc:date>2020-12-01T17:10:55Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1035301#M60333</link>
      <description>&lt;P&gt;For others looking for help in this space.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've just tested the below line in a python script that looks at a set map&amp;nbsp;(Data Editing) in the Current project, and had the last 2 lines repeated for all the different layer names that I wanted it to update. It successfully deleted the definition query from each layer.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
m = aprx.listMaps("Data Editing")[0]

for lyr in m.listLayers("Layer 1"):    ###Repeat these 2 lines for each layer
    lyr.definitionQuery = None

for lyr in m.listLayers("Layer 2"):    
    lyr.definitionQuery = None&lt;/LI-CODE&gt;&lt;P&gt;I plan to write a simple script that can be used on any project and map which will just go through all layers in the current map and wipe and definition queries. Variations of this could include a 3rd line for each layer that adds a replacement query in the originals place.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 03:05:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1035301#M60333</guid>
      <dc:creator>LindsayRaabe_FPCWA</dc:creator>
      <dc:date>2021-03-11T03:05:02Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1072662#M61494</link>
      <description>&lt;P&gt;Sorry,&amp;nbsp; lyr.definitionQuery = None&amp;nbsp; &amp;nbsp; does not work.&amp;nbsp; It still is keeping all query clauses.&amp;nbsp; &amp;nbsp;Frustrating.&lt;/P&gt;</description>
      <pubDate>Fri, 25 Jun 2021 16:32:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1072662#M61494</guid>
      <dc:creator>JimP-notUniqueAtAll</dc:creator>
      <dc:date>2021-06-25T16:32:34Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1147595#M63869</link>
      <description>&lt;P&gt;I was able to get this method to work as well. For context: I am running script tools&amp;nbsp; that allow users to set and clear definition queries for multiple layers. When setting, they select a value from a drop down list and run the script which creates and applies the query with their selected value to all the relevant layers. When clearing, they simply run the script tool and all definition queries are cleared from the relevant layers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is an example of the syntax I used for clearing queries. I am into an issue where it gave an error if the layer didn't already have a DQ on it, so it couldn't overwrite it. So I check for existing DQs first, if there is one, I overwrite it, if there isn't one, I create and apply one.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
    m = aprx.activeMap
    lyrs = m.listLayers()
    
    for lyr in lyrs:
        if lyr.name in ('TEST_PT', 'TEST_LINE', 'TEST_POLY'):
            cim_layer = lyr.getDefinition('V2')
            
            if cim_layer.featureTable.definitionFilterChoices:
                cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = None
                cim_layer.featureTable.definitionExpression = None
                
            else:
                cim_layer.featureTable.definitionExpression = None
            
            lyr.setDefinition(cim_layer)&lt;/LI-CODE&gt;&lt;P&gt;Doing it this way allowed me to create, apply, and clear definition queries without creating a massive list of deactivated queries for each layer. Hope this helps others.&lt;/P&gt;</description>
      <pubDate>Thu, 24 Feb 2022 16:48:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1147595#M63869</guid>
      <dc:creator>MikeLachance1</dc:creator>
      <dc:date>2022-02-24T16:48:29Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1331330#M68737</link>
      <description>&lt;P&gt;Mike,&lt;/P&gt;&lt;P&gt;Would love to see the whole script tool you created if you have a moment.&lt;BR /&gt;What you have created is very close to my tool.&lt;/P&gt;&lt;P&gt;Select Layers&amp;gt;choose or write query definition (or set to clear)&amp;gt;check if definition query exists &amp;gt; update definition query&lt;/P&gt;</description>
      <pubDate>Fri, 22 Sep 2023 03:37:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1331330#M68737</guid>
      <dc:creator>Joseph_Kinyon</dc:creator>
      <dc:date>2023-09-22T03:37:18Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1352045#M69264</link>
      <description>&lt;P&gt;Hi Joseph, sorry for the late reply. What is posted is the entirety of the code within my "Clear All Filters" GP script tool that my users run. Were you interested in seeing the script for setting definition queries as well?&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2023 16:20:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1352045#M69264</guid>
      <dc:creator>MikeLachance1</dc:creator>
      <dc:date>2023-11-21T16:20:46Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1592217#M73866</link>
      <description>&lt;P&gt;Hi Mike, I would be very interested in seeing how to set the definition queries.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2025 14:56:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1592217#M73866</guid>
      <dc:creator>CarsonGEO</dc:creator>
      <dc:date>2025-03-05T14:56:06Z</dc:date>
    </item>
    <item>
      <title>Re: ArcGIS Pro - Modifying Layer Definition query via ArcPY</title>
      <link>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1592236#M73867</link>
      <description>&lt;P&gt;Hi Carson,&lt;/P&gt;&lt;P&gt;Here is the part where I apply a definition query. Hope this helps:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;if lyr.name in layer_list:
                
            def_q = YOUR_DEF_QUERY
                
            cim_layer = lyr.getDefinition('V3')
            
            if cim_layer.featureTable.definitionFilterChoices:
                cim_layer.featureTable.definitionFilterChoices[0].definitionExpressionName = ''
                cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = None
                cim_layer.featureTable.definitionExpression = None
            
                cim_layer.featureTable.definitionFilterChoices[0].definitionExpression = def_q   
                cim_layer.featureTable.definitionExpression = def_q
                
            else:
                cim_layer.featureTable.definitionExpression = def_q
            
            lyr.setDefinition(cim_layer)   &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First I check if there are any definition queries already on the layer. If there are I clear them out. Then I apply mine using the .definitionExpression method. Finally I set the layer definition.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Mar 2025 15:33:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcgis-pro-modifying-layer-definition-query-via/m-p/1592236#M73867</guid>
      <dc:creator>MikeLachance1</dc:creator>
      <dc:date>2025-03-05T15:33:09Z</dc:date>
    </item>
  </channel>
</rss>

