<?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: Delete vs deactivate layer definition query in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1245927#M66429</link>
    <description>&lt;P&gt;Hi, I tried this method but did not clear the definition query for me...&lt;/P&gt;</description>
    <pubDate>Fri, 06 Jan 2023 04:13:43 GMT</pubDate>
    <dc:creator>CatherineHall678</dc:creator>
    <dc:date>2023-01-06T04:13:43Z</dc:date>
    <item>
      <title>Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2899#M243</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm trying to automate clearing an existing layer definition query and setting a new one. The code I wrote does successfully set the new def query, but it&amp;nbsp;deactivates the old query rather than actually deleting it. The&amp;nbsp;&lt;A class="jivelink1" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm#C_GUID-AE1B6592-5077-4B14-AFF1-BE41E81538CC" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm#C_GUID-AE1B6592-5077-4B14-AFF1-BE41E81538CC" rel="nofollow noopener noreferrer" target="_blank"&gt;Layer class code sample 2&lt;/A&gt;&amp;nbsp;shows how it presumably would be done, but it doesn't actually delete it.&amp;nbsp;&lt;A href="https://community.esri.com/thread/241459" target="_blank"&gt;ArcGIS Pro - Modifying Layer Definition query via ArcPY&lt;/A&gt;&amp;nbsp;also essentially asks the same question, but it was never fully answered.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; map &lt;SPAN class="keyword token"&gt;in&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="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
    lyr &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; map&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;listLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;"Zoning History"&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;
    lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; None  &lt;SPAN class="comment token"&gt;## have also tried ""&lt;/SPAN&gt;
    lyr&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;definitionQuery &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"CaseNumber = '"&lt;/SPAN&gt; &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; case &lt;SPAN class="operator token"&gt;+&lt;/SPAN&gt; &lt;SPAN class="string 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;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've tried setting it as None and "" - both result in deactivating rather than deleting the old query. It's not a showstopper, but it's kind of weird. If I change the def query again, it will overwrite the old-new query, but the old-old query (which was not set using ArcPy, if it matters) still remains present but inactive.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I started thinking about other scenarios, such as what if I &lt;EM&gt;wanted&lt;/EM&gt; to deactivate rather than delete a query? I haven't found any documentation for how to do that properly (rather than unintentionally) with ArcPy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 20:07:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2899#M243</guid>
      <dc:creator>JeffThomasILM</dc:creator>
      <dc:date>2021-12-10T20:07:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2900#M244</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Update: there's clearly something buggy with the original query on my map layers. After I manually deleted all the queries through the UI, ArcPy worked correctly when I added a new query, then changed the query to a new query, leaving no previous query as inactive. The new question is whether it's just me or if it's a bug that any layer&amp;nbsp;with an existing query set through the UI has the same issue when attempting update with ArcPy. And my other question: what if I &lt;EM&gt;wanted&lt;/EM&gt; to deactivate the def query with ArcPy?&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2020 20:41:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2900#M244</guid>
      <dc:creator>JeffThomasILM</dc:creator>
      <dc:date>2020-04-17T20:41:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2901#M245</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;See &lt;A href="https://community.esri.com/thread/241459"&gt;ArcGIS Pro - Modifying Layer Definition query via ArcPY&lt;/A&gt; , you will need to work with the &lt;A class="link-titled" href="https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm" title="https://pro.arcgis.com/en/pro-app/arcpy/mapping/python-cim-access.htm"&gt;Python CIM access—ArcPy | Documentation&lt;/A&gt; .&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 17 Apr 2020 22:51:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/2901#M245</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2020-04-17T22:51:06Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1035296#M60332</link>
      <description>&lt;P&gt;I've just tested the below line in our 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. 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;&amp;nbsp;&lt;/P&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.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Mar 2021 02:59:55 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1035296#M60332</guid>
      <dc:creator>LindsayRaabe_FPCWA</dc:creator>
      <dc:date>2021-03-11T02:59:55Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1185321#M64805</link>
      <description>&lt;P&gt;Did this issue ever get resolved? I tried using the listDefinitionQueries, setting the 'isActive' field to False and then using then using the updateDefinitionQueries function. But that just does the same thing as lyr.definitionQuery = None. So if you are iterating through multiple definition queries there is no way to automate their removal.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 23 Jun 2022 00:19:17 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1185321#M64805</guid>
      <dc:creator>adamwade1</dc:creator>
      <dc:date>2022-06-23T00:19:17Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1245927#M66429</link>
      <description>&lt;P&gt;Hi, I tried this method but did not clear the definition query for me...&lt;/P&gt;</description>
      <pubDate>Fri, 06 Jan 2023 04:13:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1245927#M66429</guid>
      <dc:creator>CatherineHall678</dc:creator>
      <dc:date>2023-01-06T04:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1254385#M66768</link>
      <description>&lt;P&gt;In my Python scripts, I use the following function to overwrite existing definition queries with new ones:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def setDefinitionQuery(layer, sqlFilter):
    layer.updateDefinitionQueries(
        [
            {'name': 'Query 1', 'sql': sqlFilter, 'isActive': True}
        ]
    )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 02 Feb 2023 16:37:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1254385#M66768</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2023-02-02T16:37:39Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1259121#M66872</link>
      <description>&lt;P&gt;this works! thank you&lt;/P&gt;</description>
      <pubDate>Thu, 16 Feb 2023 21:25:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1259121#M66872</guid>
      <dc:creator>SH_DH</dc:creator>
      <dc:date>2023-02-16T21:25:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1312184#M68251</link>
      <description>&lt;P&gt;Worked like a charm.&amp;nbsp; Thanks !&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 17:59:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1312184#M68251</guid>
      <dc:creator>BobCapezza</dc:creator>
      <dc:date>2023-07-26T17:59:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313680#M68299</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/560410"&gt;@RogerDunnGIS&lt;/a&gt;,&amp;nbsp;Thanks for providing this function.&amp;nbsp; I'm really new to python, so please correct me if I'm wrong. If I understand your function correctly, I need to provide two variables to the function: "layer", and "sqlFilter" that the function uses?&amp;nbsp; How do I call/use your function?&amp;nbsp; Thanks so much for your help.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 16:34:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313680#M68299</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-31T16:34:06Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313695#M68300</link>
      <description>&lt;P&gt;So, the layer has to be a Layer object, and typically these are obtained by getting a reference to layer within a map within a project.&amp;nbsp; The sqlFilter object is a string and must contain an SQL statement that functions on the layer, given its workspace type.&amp;nbsp; So, here's an example of how that might be used where the layer is in an enterprise geodatabase and quotes around field names are unnecessary.&amp;nbsp; The fields CHILLS, CONTROL, and SUPPLIED_POWER are numeric fields and it is hoped that they are non-null.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;proj = arcpy.mp.ArcGISProject("CURRENT") # or "C:\Grease.aprx", etc.
my_map = proj.activeMap # or proj.listMaps("Map"). Do not create a variable named map because map is a certain function in Python
my_layer = my_map.ListLayers("TheOneThatIWant")
my_filter = "CHILLS * CHILLS - CONTROL = SUPPLIED_POWER" # Do not create a variable called filter because filter is a certain function in Python
setDefinitionQuery(my_layer, my_filter)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Once this code executes, the layer named TheOneThatIWant inside the active map (or the map named "Map") inside the currently-open project (or the project at C:\Grease.aprx) will now only show features in the map &lt;EM&gt;and in the attribute table&lt;/EM&gt; where a given feature's CHILLS value squared minus its CONTROL value are equal to its SUPPLIED_POWER field.&lt;/P&gt;&lt;P&gt;This is perfect for when you've got chills, they're multiplyin', and you're losing control, because the power you're supplying, is electrifying.&amp;nbsp; Your map will really shape up after this.&amp;nbsp; Let me know if you have any more questions.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 17:02:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313695#M68300</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2023-07-31T17:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313860#M68304</link>
      <description>&lt;P&gt;I finally figured out how to REMOVE/DELETE the definition query from a specific layer in a specific map.&amp;nbsp; Ultimately, I used the Cartographic Information Model (cim) to access the definitionExpression.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I read through the Python CIM access web page.&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/python-cim-access.htm" target="_self"&gt;https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/python-cim-access.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;In my aprx file, I right-clicked the map's name and selected "Save As Map File" the map(s), and them opened the *.mapx file as a *.json file.&amp;nbsp; Next, I searched through the file for the "definitionExpression" field.&amp;nbsp; After trying a bunch of things, I finally found that I want to change the layers "featureTable.definitionExpression" to equal "".&lt;/P&gt;&lt;P&gt;Here's my code.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
# Reference a project, map, and layer using arcpy.mp
aprx = arcpy.mp.ArcGISProject('current')
m = aprx.listMaps("Inset")[0]
lyr = m.listLayers("AZ811 BlueStake")[0]
# Return the layer's CIM definition
cim_lyr = lyr.getDefinition('V2')
# Modify the featureTable.definitionExpression
cim_lyr.featureTable.definitionExpression = ""
# Push the changes back to the layer object
lyr.setDefinition(cim_lyr)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 20:50:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313860#M68304</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-31T20:50:45Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313880#M68308</link>
      <description>&lt;P&gt;Oh, I didn't know you wanted to&amp;nbsp;&lt;EM&gt;remove&lt;/EM&gt; the definition query; I thought you wanted to do what the OP was asking: set a new definition query and forget the old ones.&amp;nbsp; To remove definition queries on a layer, you set the layer's definitionQuery property to None.&amp;nbsp; If you're new to Python, I would advise staying away from the Cartographic Information Model.&amp;nbsp; Even with years of Python experience under my belt, and even more in other languages, I stay away from it myself.&amp;nbsp; It's very sensitive to prodding and changes.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 23:00:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313880#M68308</guid>
      <dc:creator>RogerDunnGIS</dc:creator>
      <dc:date>2023-07-31T23:00:47Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313883#M68309</link>
      <description>&lt;P&gt;I tried to set the definitionQuery property to "" and None.&amp;nbsp; All that happened was the layer's definition query was made inactive and the new definition query was created and made active.&amp;nbsp; &amp;nbsp;Thanks for your advice.&amp;nbsp; I will just have to accept that I will have to delete the old definition query from within the aprx.&lt;/P&gt;</description>
      <pubDate>Mon, 31 Jul 2023 23:11:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1313883#M68309</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-31T23:11:59Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1319285#M68434</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/239209"&gt;@adamwade1&lt;/a&gt;&amp;nbsp;, the only solution that I found to work was to use the function provided by&amp;nbsp;@RogerDunnGIS&lt;SPAN class=""&gt;&lt;SPAN class=""&gt;‎ on 02-02-2023&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class=""&gt;08:37 AM (see above in this thread).&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 19:00:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1319285#M68434</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-08-16T19:00:29Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1331729#M68742</link>
      <description>&lt;P&gt;This is great stuff, thanks for sharing.&amp;nbsp;&lt;BR /&gt;Another thanks to Roger Dunn and Joshua Bixby&lt;BR /&gt;While it isn't the prettiest or even complete, I shoe horned it into a script tool in model builder to make use of the Iterate Multivalue tool in ArcGIS 3&lt;BR /&gt;The script is called Definition Query Update in the model image.&lt;BR /&gt;I thought I'd add back how it worked for my needs.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;"""
Script documentation
- Tool parameters are accessed using arcpy.GetParameter() or 
                                     arcpy.GetParameterAsText()
- Update derived parameter values using arcpy.SetParameter() or
                                        arcpy.SetParameterAsText()
"""
import arcpy
def script_tool(param0, param1, param3):
    """Script code goes below"""
    return
#get the input paramaters passed from the model output and variables
param0 = arcpy.GetParameterAsText(0)
param1 = arcpy.GetParameterAsText(1)
param3 = arcpy.GetParameterAsText(3)
aprx = arcpy.mp.ArcGISProject('current')
m = aprx.listMaps()[0]
l = m.listLayers()[0]
#limit changes to the list of layers selected, in this version layers cannot be in a layer group to work
for l in m.listLayers(param0):
    if l.supports('DefinitionQuery'):
       #Get the list of definition queries
        dql = l.listDefinitionQueries()
       #Clear active definition queries otherwise the update will fail if there is already an active query
        for dq in dql:
            dq['isActive'] = False
       #Create a new definition query and append it to the list
        dql.append({'name': param3, 'sql' : param1, 'isActive': True})
       #Update the definition queries with the newly modified list
        l.updateDefinitionQueries(dql) 
    
arcpy.SetParameterAsText(2, param1)
arcpy.AddMessage(param0)
arcpy.AddMessage(param1)
arcpy.AddMessage(param3)
#consider inserting a file picker variable that allows you to select an existing definition query .exp file for the sql input&lt;/LI-CODE&gt;&lt;P&gt;&lt;BR /&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.JPG" style="width: 825px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/81455i5C9631DE3F049002/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.JPG" alt="Capture.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 23 Sep 2023 00:22:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1331729#M68742</guid>
      <dc:creator>Joseph_Kinyon</dc:creator>
      <dc:date>2023-09-23T00:22:48Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1384348#M69918</link>
      <description>&lt;P&gt;I am not super familiar with functions so I ended up going this route based on&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/560410"&gt;@RogerDunnGIS&lt;/a&gt;&amp;nbsp;tip above&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#Set definition query for Main Map
map_obj = aprx.listMaps(map_name)[0]
layer_obj = map_obj.listLayers(layer_name)[0]
definition_query = f"{field_name} = '{query_value}'"
layer_obj.updateDefinitionQueries([
    {'name': 'Query 1', 'sql': definition_query, 'isActive': True}
    ])&lt;/LI-CODE&gt;</description>
      <pubDate>Tue, 20 Feb 2024 14:31:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1384348#M69918</guid>
      <dc:creator>edward33</dc:creator>
      <dc:date>2024-02-20T14:31:49Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1476809#M70636</link>
      <description>&lt;P&gt;In order to delete (not deactivate) a definition query:&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;import arcpy

# Choose your layer
layer = r"MyLayer"
# Choose your project
project = arcpy.mp.ArcGISProject("CURRENT")
# Choose your map
m = project.listMaps()[0]
# Remove definition queries
for lyr in m.listLayers(layer): 
    lyr.updateDefinitionQueries([])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT&gt;As we can see above that updateDefinitionQueries() take a list as parameter, so an empty list will result in an empty definition query. We could also set multiple definition queries if needed:&lt;/FONT&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;lyr.updateDefinitionQueries([
{'name': 'Query 1', 'sql': "myfield1 = 'stuff1', 'isActive': True},
{'name': 'Query 2', 'sql': "myfield2 = 'stuff2', 'isActive': True}
])&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;HR /&gt;&lt;P&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 09:21:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1476809#M70636</guid>
      <dc:creator>Bastien</dc:creator>
      <dc:date>2024-05-22T09:21:33Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1514360#M71198</link>
      <description>&lt;P&gt;Works perfectly! Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 02 Aug 2024 19:08:37 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1514360#M71198</guid>
      <dc:creator>MK13</dc:creator>
      <dc:date>2024-08-02T19:08:37Z</dc:date>
    </item>
    <item>
      <title>Re: Delete vs deactivate layer definition query</title>
      <link>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1567421#M73319</link>
      <description>&lt;P&gt;Here is the code that&amp;nbsp; should do what you want:&amp;nbsp;&lt;/P&gt;&lt;P&gt;import arcpy&lt;/P&gt;&lt;P&gt;# Access the active project&lt;BR /&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;/P&gt;&lt;P&gt;# Access the active map&lt;BR /&gt;map_obj = aprx.activeMap&lt;/P&gt;&lt;P&gt;# Check if there is an active map&lt;BR /&gt;if map_obj is None:&lt;BR /&gt;print("No active map found.")&lt;BR /&gt;else:&lt;BR /&gt;# Access layers in the active map&lt;BR /&gt;layers = map_obj.listLayers()&lt;/P&gt;&lt;P&gt;# Loop through all layers and remove their definition queries&lt;BR /&gt;for layer in layers:&lt;BR /&gt;if layer.supports("DEFINITIONQUERY"):&lt;BR /&gt;try:&lt;BR /&gt;# Update the definition query with an empty list to remove it&lt;BR /&gt;layer.updateDefinitionQueries([]) # Attempt to clear the query&lt;BR /&gt;print(f"Definition query for '{layer.name}' removed.")&lt;BR /&gt;except Exception as e:&lt;BR /&gt;print(f"Failed to update definition query for '{layer.name}': {e}")&lt;/P&gt;&lt;P&gt;# Save the project&lt;BR /&gt;aprx.save()&lt;/P&gt;&lt;P&gt;# Clean up&lt;BR /&gt;del aprx&lt;/P&gt;</description>
      <pubDate>Wed, 11 Dec 2024 19:39:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/delete-vs-deactivate-layer-definition-query/m-p/1567421#M73319</guid>
      <dc:creator>Miralem_Zeljo</dc:creator>
      <dc:date>2024-12-11T19:39:23Z</dc:date>
    </item>
  </channel>
</rss>

