<?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: Need to change a layer's definition query in two maps (main and inset) of a single layout. in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312225#M68254</link>
    <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;Thanks for the link!&amp;nbsp;&amp;nbsp;Maybe I missed something.&lt;/P&gt;&lt;P&gt;Here's the link for Pro 2.9 -&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/layer-class.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/layer-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jul 2023 18:48:34 GMT</pubDate>
    <dc:creator>Shauna-RaeBrown</dc:creator>
    <dc:date>2023-07-26T18:48:34Z</dc:date>
    <item>
      <title>Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312132#M68250</link>
      <description>&lt;P&gt;I've written a python script (arcpy) that takes the text from an email containing a ticket number and lat/long coordinates.&amp;nbsp; I've been able to extract the data containing the ticket number, lat/long coordinates that form a rectangle, and other data.&amp;nbsp; This data is a list that updates a featureclass in a file gdb.&amp;nbsp; I've also updated/changed the layout's name to reflect the ticket number.&amp;nbsp; The feature class/layer is used in both the main map and a reference or inset map.&amp;nbsp; The aprx has 2 maps, and one layout.&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I can't figure out is how to change the layer's definition query, so that I can zoom to or pan to the new feature.&amp;nbsp; I think I need to use the Cartographic Information Model (cim), but I'm not sure how to change the layer's definition query.&lt;/P&gt;&lt;P&gt;I'm working in ArcGIS Pro 2.9&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 17:10:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312132#M68250</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-26T17:10:21Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312215#M68253</link>
      <description>&lt;P&gt;CIM, layer class, definition query is read/write&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>Wed, 26 Jul 2023 18:42:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312215#M68253</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-07-26T18:42:24Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312225#M68254</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;Thanks for the link!&amp;nbsp;&amp;nbsp;Maybe I missed something.&lt;/P&gt;&lt;P&gt;Here's the link for Pro 2.9 -&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/layer-class.htm" target="_blank"&gt;https://pro.arcgis.com/en/pro-app/2.9/arcpy/mapping/layer-class.htm&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 18:48:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312225#M68254</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-26T18:48:34Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312234#M68255</link>
      <description>&lt;P&gt;code examples at the bottom if that is what you are looking for&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 18:59:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312234#M68255</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-07-26T18:59:48Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312282#M68257</link>
      <description>&lt;P&gt;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;,&amp;nbsp;Thanks for your help.&amp;nbsp; I've been working on adapting example 4, but I keep getting an error.&amp;nbsp; I think it has to do with the&amp;nbsp;ticketNo = "2023070700400.002".&amp;nbsp; That field in my feature class is a text field.&amp;nbsp; I've tried tickeNo = str(2023070700400.002) and I get the same error.&amp;nbsp; Of course it could have to do with my sql query.&amp;nbsp; I'm stumped.&amp;nbsp; Thanks for ANY help that you can offer.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
ticketNo = "2023070700400.002"
m = aprx.listMaps()[0]
l = m.listLayers("AZ811 BlueStake")[0]
if l.supports('DefinitionQuery'):
  #Get the list of definition queries
  dql = l.listDefinitionQueries('Query 1')[0]
  #Clear active definition query, 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': 'Query 1', 'sql': "tktNum = ticketNo", 'isActive': True})
  #Update the definition queries with the newly modified list
  l.updateDefinitionQueries(dql)

Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 10, in &amp;lt;module&amp;gt;
TypeError: 'str' object does not support item assignment&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jul 2023 20:23:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312282#M68257</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-26T20:23:22Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312336#M68258</link>
      <description>&lt;P&gt;You changed it from a list to a string in line 10 so you can't cycle through it as you appear to want to do.&lt;/P&gt;&lt;P&gt;Their line is&lt;/P&gt;&lt;LI-CODE lang="python"&gt;dql = l.listDefinitionQueries()&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 26 Jul 2023 21:49:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312336#M68258</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2023-07-26T21:49:59Z</dc:date>
    </item>
    <item>
      <title>Re: Need to change a layer's definition query in two maps (main and inset) of a single layout.</title>
      <link>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312784#M68269</link>
      <description>&lt;P&gt;I mostly figured it out!&amp;nbsp;&amp;nbsp;However, it created another Query 1 with the correct definition query, and it added the definition query to both maps.&amp;nbsp; See my code below.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
ticketNo = "2023070700400.002"
fieldname = "tktNum"
newName = str.format(ticketNo)
for m in aprx.listMaps():
  for l in m.listLayers("AZ811 BlueStake"):
    if l.supports('DefinitionQuery'):
      #Get the list of definition queries
      dql = l.listDefinitionQueries('Query 1')
      #Clear active definition query, 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': 'Query 1', 'sql': """{} = '{}'""".format(fieldname,newName), 'isActive': True})
      #Update the definition queries with the newly modified list
      l.updateDefinitionQueries(dql)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;Now, I just need to figure out how to have just the one definition query on the layer.&amp;nbsp; Thanks for your help&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/215600"&gt;@DanPatterson&lt;/a&gt;&amp;nbsp;!&lt;/P&gt;</description>
      <pubDate>Thu, 27 Jul 2023 19:32:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/need-to-change-a-layer-s-definition-query-in-two/m-p/1312784#M68269</guid>
      <dc:creator>Shauna-RaeBrown</dc:creator>
      <dc:date>2023-07-27T19:32:23Z</dc:date>
    </item>
  </channel>
</rss>

