<?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: Definition query is not running correctly when the path of the aprx file is given. in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566256#M91023</link>
    <description>&lt;P&gt;it wasnt the layer being saved, but the project&lt;/P&gt;</description>
    <pubDate>Mon, 09 Dec 2024 15:51:14 GMT</pubDate>
    <dc:creator>DanPatterson</dc:creator>
    <dc:date>2024-12-09T15:51:14Z</dc:date>
    <item>
      <title>Definition query is not running correctly when the path of the aprx file is given.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566193#M91015</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;I am newbie to arcpy scripting. I have written the following script based on referring to previous posts. This script remove definition query for a layer in a map.&lt;/P&gt;&lt;P&gt;I run this in the python console of ArcMap.&lt;/P&gt;&lt;P&gt;The query works fine when giving path of the aprx as CURRENT. It removes the existing definition query.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;P&gt;The same query also runs when the path of the aprx is given. But it doest remove definition query&lt;/P&gt;&lt;P&gt;aprx = arcpy.mp.ArcGISProject(r'C:\08_GIS\Arc\MyProject9_Test.aprx')&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    # Specify the path to your ArcGIS project
    #aprx = arcpy.mp.ArcGISProject("CURRENT")
    aprx = arcpy.mp.ArcGISProject(r'C:\08_GIS\Arc\99_temp_work\MyProject9_Test.aprx')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;## This script removes all definition query in Map layers in Apro
import arcpy
import os

def remove_definition_query(layer_name, my_map=None):
    # Specify the path to your ArcGIS project
    #aprx = arcpy.mp.ArcGISProject("CURRENT")
    aprx = arcpy.mp.ArcGISProject(r'C:\08_GIS\Arc\99_temp_work\MyProject9_Test.aprx')
    
    # Iterate through maps in the project
    for map in aprx.listMaps():
        # Check if a specific map is provided
        if my_map and map.name != my_map:
            continue
        
        print(f"Checking map: {map.name}")  # Debugging line
        
        # Iterate through layers in the map
        for layer in map.listLayers():
            print(f"Found layer: {layer.name}")  # Debugging line
            if layer.name == layer_name:
                try:
                    # Remove the definition query by setting it to None
                    layer.definitionQuery = None
                    print(f"Removed definition query for layer: {layer_name} in map: {map.name}")
                
                except Exception as e:
                    print(f"Error removing definition query for layer {layer_name} in map {map.name}: {e}")

remove_definition_query("LFS_Replenishment_2_Dissolve1", 'TestMap1')&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Query Output:&lt;/P&gt;&lt;P&gt;Checking map: TestMap1&lt;BR /&gt;Found layer: LFS`1&lt;BR /&gt;Found layer: LFS_Replenishment_2_Dissolve1&lt;BR /&gt;Removed definition query for layer: LFS_Replenishment_2_Dissolve1 in map: TestMap1&lt;BR /&gt;Found layer: MapGeniePremiumITM&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can someone tell me why this is query is not working correctly when given the path. I appreciate your help on this.&lt;/P&gt;&lt;P&gt;matter. FYI: The path file is correct.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 13:48:31 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566193#M91015</guid>
      <dc:creator>mohanalogakrishnan</dc:creator>
      <dc:date>2024-12-09T13:48:31Z</dc:date>
    </item>
    <item>
      <title>Re: Definition query is not running correctly when the path of the aprx file is given.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566200#M91016</link>
      <description>&lt;P&gt;In Pro example 2, they save the aprx when they are done, give it a try&lt;/P&gt;&lt;P&gt;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm" target="_blank"&gt;Layer—ArcGIS Pro | Documentation&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 14:05:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566200#M91016</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-12-09T14:05:03Z</dc:date>
    </item>
    <item>
      <title>Re: Definition query is not running correctly when the path of the aprx file is given.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566210#M91017</link>
      <description>&lt;P&gt;Thank you for your time Dan,&lt;/P&gt;&lt;P&gt;I did tried saving to a new layer file. It saves but the saved the file is similar to that of input ones. It didn't remove definition query.&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 14:37:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566210#M91017</guid>
      <dc:creator>mohanalogakrishnan</dc:creator>
      <dc:date>2024-12-09T14:37:16Z</dc:date>
    </item>
    <item>
      <title>Re: Definition query is not running correctly when the path of the aprx file is given.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566256#M91023</link>
      <description>&lt;P&gt;it wasnt the layer being saved, but the project&lt;/P&gt;</description>
      <pubDate>Mon, 09 Dec 2024 15:51:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566256#M91023</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2024-12-09T15:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: Definition query is not running correctly when the path of the aprx file is given.</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566533#M91065</link>
      <description>&lt;OL&gt;&lt;LI&gt;&amp;nbsp;as &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp; notes, you need to save the aprx. e.g. &lt;FONT face="courier new,courier"&gt;aprx.save()&lt;/FONT&gt;&lt;/LI&gt;&lt;LI&gt;if are you trying to run that code in ArcGIS Pro with that aprx open, that won't work. When you open a project in Pro, it reads it into memory. Any changes you make to the underlying .aprx on disk will not be reflected in the current Pro session. Have you tried running the code, then opening the aprx in a new Pro session?&lt;/LI&gt;&lt;/OL&gt;</description>
      <pubDate>Tue, 10 Dec 2024 00:39:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/definition-query-is-not-running-correctly-when-the/m-p/1566533#M91065</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2024-12-10T00:39:19Z</dc:date>
    </item>
  </channel>
</rss>

