<?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: Python definition query - conversion from version 2 to 3 in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101355#M7863</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried the code?&amp;nbsp; If so, what was the first error?&amp;nbsp; (I am guessing Line 02).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your question/issue doesn't involve any Python 2 to Python 3 issues.&amp;nbsp; The issue you are running into has to do with the ArcGIS Pro GUI being significantly different than ArcMap, and the ArcGIS Pro mapping module being completely new to address the restructured Pro GUI.&amp;nbsp; In short, it is an ArcMap to ArcGIS Pro ArcPy conversion issue, not a Python version conversion issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the ArcGIS Pro GUI is so different than ArcMap GUI, I suggest you read through the ArcGIS Pro&amp;nbsp; documentation to get familiar with how the new ArcPy mapping module works.&amp;nbsp; Updating the query definition itself is the same between Pro and ArcMap, it is getting access to the layers that is different between the two:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;map_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# name of Pro map tab containing layers to be updated&lt;/SPAN&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;
map &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;map_name&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="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;"CONDO_1ST_LEVEL*"&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; &lt;SPAN class="string token"&gt;'"SUBCODE" =\'1172\''&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:16:03 GMT</pubDate>
    <dc:creator>JoshuaBixby</dc:creator>
    <dc:date>2021-12-11T06:16:03Z</dc:date>
    <item>
      <title>Python definition query - script created in ArcMap to be used in Pro</title>
      <link>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101354#M7862</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;My goal is to create a script that applies a definition query to multiple layers in ArcGIS Pro. I was able to successfully create a script (not the most elegant) in ArcMap and not knowing that the GUI is different in Pro and causing errors to my script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm new to Python and doing my best to recreate this script in ArcGIS Pro, but having difficulty especially using the listLayer.&amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="text-decoration: underline; font-size: 22px;"&gt;&lt;STRONG&gt;Here's my script created in ArcMap:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd,"CONDO_1ST_LEVEL*")
#replace subcode here
query = '"SUBCODE" =\'1172\''
layers[0].definitionQuery=query
print layers [0].definitionQuery
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd,"CONDO_2ND_LEVEL*")
#replace subcode here
query = '"SUBCODE" =\'1172\''
layers[0].definitionQuery=query
print layers [0].definitionQuery
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd,"CONDO_3RD_LEVEL*")
#replace subcode here
query = '"SUBCODE" =\'1172\''
layers[0].definitionQuery=query
print layers [0].definitionQuery
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd,"CONDO_4TH_LEVEL*")
#replace subcode here
query = '"SUBCODE" =\'1172\''
layers[0].definitionQuery=query
print layers [0].definitionQuery
mxd = arcpy.mapping.MapDocument("CURRENT")
layers = arcpy.mapping.ListLayers(mxd,"CONDO_5TH_LEVEL*")
#replace subcode here
query = '"SUBCODE" =\'1172\''
layers[0].definitionQuery=query
print layers [0].definitionQuery
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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;&lt;SPAN style="text-decoration: underline; font-size: 22px;"&gt;&lt;STRONG&gt;Here's my attempt to convert the script to version 3 to use in ArcGIS Pro:&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;aprx = arcpy.mp.ArcGISProject("CURRENT")
lyr = m.listLayers(aprx,"CONDO_1ST_LEVEL*")[0]
#replace subcode here
query = '"SUBCODE" =\'1172\''
m.listLayers[0].definitionQuery=query
print (layers [0].definitionQuery)
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyr = m.listLayers(aprx,"CONDO_2ND_LEVEL*")[0]
#replace subcode here
query = '"SUBCODE" =\'1172\''
m.listLayers[0].definitionQuery=query
print (layers [0].definitionQuery)
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyr = m.listLayers(aprx,"CONDO_3RD_LEVEL*")[0]
#replace subcode here
query = '"SUBCODE" =\'1172\''
m.listLayers[0].definitionQuery=query
print (layers [0].definitionQuery)
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyr = m.listLayers(aprx,"CONDO_4TH_LEVEL*")[0]
#replace subcode here
query = '"SUBCODE" =\'1172\''
m.listLayers[0].definitionQuery=query
print (layers [0].definitionQuery)
aprx = arcpy.mp.ArcGISProject("CURRENT")
lyr = m.listLayers(aprx,"CONDO_5TH_LEVEL*")[0]
#replace subcode here
query = '"SUBCODE" =\'1172\''
m.listLayers[0].definitionQuery=query
print (layers [0].definitionQuery)
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/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;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 06:16:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101354#M7862</guid>
      <dc:creator>PeteCoventry3</dc:creator>
      <dc:date>2021-12-11T06:16:00Z</dc:date>
    </item>
    <item>
      <title>Re: Python definition query - conversion from version 2 to 3</title>
      <link>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101355#M7863</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Have you tried the code?&amp;nbsp; If so, what was the first error?&amp;nbsp; (I am guessing Line 02).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your question/issue doesn't involve any Python 2 to Python 3 issues.&amp;nbsp; The issue you are running into has to do with the ArcGIS Pro GUI being significantly different than ArcMap, and the ArcGIS Pro mapping module being completely new to address the restructured Pro GUI.&amp;nbsp; In short, it is an ArcMap to ArcGIS Pro ArcPy conversion issue, not a Python version conversion issue.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Since the ArcGIS Pro GUI is so different than ArcMap GUI, I suggest you read through the ArcGIS Pro&amp;nbsp; documentation to get familiar with how the new ArcPy mapping module works.&amp;nbsp; Updating the query definition itself is the same between Pro and ArcMap, it is getting access to the layers that is different between the two:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;map_name &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; &lt;SPAN class="comment token"&gt;# name of Pro map tab containing layers to be updated&lt;/SPAN&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;
map &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;map_name&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="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;"CONDO_1ST_LEVEL*"&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; &lt;SPAN class="string token"&gt;'"SUBCODE" =\'1172\''&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;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:16:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101355#M7863</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2021-12-11T06:16:03Z</dc:date>
    </item>
    <item>
      <title>Re: Python definition query - conversion from version 2 to 3</title>
      <link>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101356#M7864</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Joshua&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks so much for the reply and clarification that it's more of a GUI issue than a Python 2 to Python 3 issue.&amp;nbsp; Again, I'm very new to this and appreciate the clarification.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've updated my question so that it more accurately addresses the issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Yes, when I ran the script created in ArcMap in Pro it was line 2 that I was receiving the following error:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Traceback (most recent call last):&lt;BR /&gt; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;NameError: name 'm' is not defined&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I ran the script you've provided and it worked perfectly!!&amp;nbsp; Thanks so much!!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 03 Nov 2017 20:10:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-definition-query-script-created-in-arcmap/m-p/101356#M7864</guid>
      <dc:creator>PeteCoventry3</dc:creator>
      <dc:date>2017-11-03T20:10:56Z</dc:date>
    </item>
  </channel>
</rss>

