<?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: Use Arcpy to Unselect the currently selected Features in all layers in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64425#M5257</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have a script that unselects all the selected features in my Map view but it loops through each layer in the dataframe and this takes a lot of time. I want to write a script that would be as fast as the Unselect the currently selected Features in all layers within ArcMap itself? This is my code below;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6461, in SelectLayerByAttribute&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Table View. ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Any Suggestions? Thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Strange, if I run the (slightly changed) code it does run for me (in 10.2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
dfs = arcpy.mapping.ListDataFrames(mxd)
for df in dfs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; for tbl in arcpy.mapping.ListTableViews(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(tbl,"CLEAR_SELECTION")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What type of layers do you have in your TOC?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 10 Dec 2021 22:28:24 GMT</pubDate>
    <dc:creator>XanderBakker</dc:creator>
    <dc:date>2021-12-10T22:28:24Z</dc:date>
    <item>
      <title>Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64423#M5255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have a script that unselects all the selected features in my Map view but it loops through each layer in the dataframe and this takes a lot of time. I want to write a script that would be as fast as the Unselect the currently selected Features in all layers within ArcMap itself? This is my code below;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6461, in SelectLayerByAttribute&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Table View. ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Any Suggestions? Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 15 Oct 2013 11:42:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64423#M5255</guid>
      <dc:creator>OLANIYANOLAKUNLE</dc:creator>
      <dc:date>2013-10-15T11:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64424#M5256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I don't believe the capability exists within arcpy to 'wholesale' clear all selected features in the active dataframe...the way you are currently using the method to clear each layer is pretty much it.&amp;nbsp; Unless you want to delve into ArcObjects...or, say, use the comtypes 'wrapper' to basically invoke the ArcObjects methods not readily available via arcpy.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Perhaps not the prime place to post about ArcObjects - I'll be brief though...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;You raised an interesting topic (for which I see there have been no posted responses yet)...however, it is kind of intriguing that although continuing support for VBA is no longer provided (no new features), this code still works at 10.0 - I just tested the following on my 10.0 (and probably it still works at 10.1, and 10.2?...I have not yet migrated my VBA authorizations above 10.0 and will likely adapt something like this as VB.NET in the future).&amp;nbsp; Here is the working VBA code to clear all selected features for all layers in the active data frame --- just for 'honorable mention', and it's so clean and simple:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Sub ClearSelection()

Dim pApp As IApplication
Set pApp = Application

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

Dim pMap As IMap
Set pMap = pMxDoc.ActiveView

Dim pAV As IActiveView
Set pAV = pMap

pMap.ClearSelection
pAV.Refresh

Debug.Print "done!"
End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:21 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64424#M5256</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-10T22:28:21Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64425#M5257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have a script that unselects all the selected features in my Map view but it loops through each layer in the dataframe and this takes a lot of time. I want to write a script that would be as fast as the Unselect the currently selected Features in all layers within ArcMap itself? This is my code below;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
Runtime error&amp;nbsp; Traceback (most recent call last):&amp;nbsp;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 2, in &amp;lt;module&amp;gt;&amp;nbsp;&amp;nbsp; File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6461, in SelectLayerByAttribute&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Table View. ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;Any Suggestions? Thanks&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Strange, if I run the (slightly changed) code it does run for me (in 10.2)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
dfs = arcpy.mapping.ListDataFrames(mxd)
for df in dfs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; for tbl in arcpy.mapping.ListTableViews(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(tbl,"CLEAR_SELECTION")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;What type of layers do you have in your TOC?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Kind regards,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64425#M5257</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2021-12-10T22:28:24Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64426#M5258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Strange, if I run the (slightly changed) code it does run for me (in 10.2)&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
dfs = arcpy.mapping.ListDataFrames(mxd)
for df in dfs:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for lyr in arcpy.mapping.ListLayers(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.isFeatureLayer:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")

&amp;nbsp;&amp;nbsp;&amp;nbsp; for tbl in arcpy.mapping.ListTableViews(mxd,"*",df):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(tbl,"CLEAR_SELECTION")
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;What type of layers do you have in your TOC?&lt;BR /&gt;&lt;BR /&gt;Kind regards,&lt;BR /&gt;&lt;BR /&gt;Xander&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Yeah, your code works but it takes the same time with what I have to go through each of the layers one after the other? I want something as fast as the&amp;nbsp; " to Unselect the currently selected Features in all layers" in ArcMap&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64426#M5258</guid>
      <dc:creator>OLANIYANOLAKUNLE</dc:creator>
      <dc:date>2021-12-10T22:28:27Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64427#M5259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Sadly this is not possible, you need to cycle through each layer &lt;span class="lia-unicode-emoji" title=":disappointed_face:"&gt;😞&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Oct 2013 19:03:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64427#M5259</guid>
      <dc:creator>TimWitt</dc:creator>
      <dc:date>2013-10-18T19:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64428#M5260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Yes that is good code Xander posted; however I think what confused him was your question wasn't related to the error in the code you posted.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;No you do not have the same access with arcpy as you do with the system ArcMap button to 'Clear Selected Features'.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe you can rig something to access ArcObjects with comtypes...but I think that's beyond the scope of this thread?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Oct 2013 19:06:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64428#M5260</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-10-18T19:06:57Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64429#M5261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Wayne is right, ArcObjects will be the way to go. It is possible to use COM objects (ArcObjects) in Python. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;If you want to know a bit more, the following links may be helpful:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://forums.arcgis.com/threads/2567-Accessing-ArcObjects-through-Python"&gt;http://forums.arcgis.com/threads/2567-Accessing-ArcObjects-through-Python&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf"&gt;http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf&lt;/A&gt;&lt;BR /&gt;&lt;A href="http://stackoverflow.com/questions/12190807/com-objects-arcobjects-in-python"&gt;http://stackoverflow.com/questions/12190807/com-objects-arcobjects-in-python&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Xander&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 21 Oct 2013 05:43:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64429#M5261</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2013-10-21T05:43:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64430#M5262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I'd like to post again both a VBA snippet and the Python comtypes equivalent... I don't know why I did not shorten the code in post #2 above to clear all selected features in the view (the current view, otherwise known as the 'focus map') to that listed below, effectively the same:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Sub ClearSelection()

Dim pMxDoc As IMxDocument
Set pMxDoc = ThisDocument

pMxDoc.FocusMap.ClearSelection
pMxDoc.ActiveView.Refresh

End Sub
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Basically, the above is a VBA subroutine (called by the name ClearSelection) that sets a document object to the currently loaded mxd, clears the selection in the entire 'focus map', and refreshes the view (to show all feature selections have been cleared).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I don't think you can test this code any longer at 10.1, but you can at 10.0 if you've authorized (for free, and depending on availability) the VBA 'extension' with ESRI.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That's about as simple as you can write ArcObject code,&amp;nbsp; using VBA...&amp;nbsp; Only reason I wanted to show that is for comparison purposes, particularly for anyone interested in migrating VBA code to Python, using comtypes.&amp;nbsp; I am yet relatively unfamiliar with comtypes but figured if there's a place to at least start the 'test drive', this oh-so-simple sample would be as good as any.&amp;nbsp; So, without further ado, here it is - I am sure you can see the similarities:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import Snippets
import comtypes
from Snippets import CType

a = Snippets.GetApp()
from comtypes.gen.esriArcMapUI import *

mxDoc = CType(a.Document, IMxDocument)
mxDoc.FocusMap.ClearSelection()
mxDoc.ActiveView.Refresh()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Once everything is loaded, it is fast... also, once the document obj mxDoc is instantiated, only the last 2 commands need be executed on successive feature selection clearing.&amp;nbsp; Of course, to be able to launch this, you need to install comtypes, downloaded from SourceForge.&amp;nbsp; You also need a Snippets module - thanks very much for the 10.0-adapted module by Corey Blakeborough&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;of SSP Innovations and Mark Cederholm who wrote the original.&amp;nbsp; The adapted version (which I used in the above 'clear selection' snippet) is at the link below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://www.sspinnovations.com/sites/default/files/assets/assets/SCRIPTS/Snippets.py" rel="nofollow noopener noreferrer" target="_blank"&gt;http://www.sspinnovations.com/sites/default/files/assets/assets/SCRIPTS/Snippets.py&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;All I've got for now...this is just a very thin opening to the heap of things you can do with ArcObjects.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64430#M5262</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-10T22:28:30Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64431#M5263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Comtypes is probably the only solution where it will be as fast as the button. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If that's not an option for whatever reason, you could keep track of the layers with selected features in a list and loop through that instead of hitting every layer. Still not great, but better.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 23 Oct 2013 20:09:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64431#M5263</guid>
      <dc:creator>MattSayler</dc:creator>
      <dc:date>2013-10-23T20:09:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64432#M5264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Via a Python solution, how about checking for any selected features before you try to unselect? Which may be faster or may be slower than not checking... Describe is pretty fast, so it might be worth the extra overhead.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if len(arcpy.Describe(lyr).fidSet) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;BTW: Good to meet you last week Matt S.!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64432#M5264</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-10T22:28:32Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64433#M5265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure if ArcObjects/ComTypes is totally neccesssary here. Also, going back to the original post... The 3rd line should be:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers(df):&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers(mxd):&lt;/PRE&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In arcpy-land, the trick is to turn the layers' visibility off 1st, clear the selection(s), then turn the visible layer back on. Otherwise it want's to redraw every loop... which is really slow.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;A little cluncky and verbose (might take out the .fidSet part - not sure if it would help that much). For me, this code takes 2 seconds to do the actual unselecting for ~6 layers with 20k features selcted... And then a redraw, which also takes time. The ArcMap unselect tool takes like 0.25 seconds... And DOESN'T have to redraw! &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrList = arcpy.mapping.ListLayers(df)
lyrDict = {}
for lyr in lyrList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDict[lyr] = [lyr.visible, False]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(arcpy.Describe(lyr).fidSet) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDist[lyr][1] = True
for lyr in lyrDict: #turn any visible layers off
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrDict[lyr][0] == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = False
arcpy.RefreshActiveView()
for lyr in lyrDict: #clear selections
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrDict[lyr][1] == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
for lyr in lyrDict: #turn any previously visible layers back on
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyrDict[lyr][0] == True: 
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = True
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT: Fewer lines - with comprehensions!&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyrDict = {}
for lyr in arcpy.mapping.ListLayers(df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDict[lyr] = [lyr.visible, False]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(arcpy.Describe(lyr).fidSet) &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; lyrDist[lyr][1] = True
for lyr in [lyr for lyr in lyrDict if lyrDict[lyr][0] == True]:&amp;nbsp; #turn any visible layers off
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = False
arcpy.RefreshActiveView()
for lyr in [lyr for lyr in lyrDict if lyrDict[lyr][1] == True]: #clear selections
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
for lyr in [lyr for lyr in lyrDict if lyrDict[lyr][0] == True]: #turns layers back on 
&amp;nbsp;&amp;nbsp;&amp;nbsp; lyr.visible = True
arcpy.RefreshActiveView()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64433#M5265</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-10T22:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64434#M5266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It'd be nice if the layer object from arcpy.mapping had some sort of 'selected set' property via arcpy.mapping. Seems all the other layer properties (like .definitionQuery, .name, etc) make it across from the good ole' Describe object ... Why no .fidSet!?!?!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers(df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if len(lyr.fidSet) &amp;gt; 0: #BTW: Wish the .fidSet property returned a native Python list!
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blah blah&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Maybe even:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;for lyr in arcpy.mapping.ListLayers(df):
&amp;nbsp;&amp;nbsp;&amp;nbsp; if lyr.hasSelection == True:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; blah blah&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hoping for some extra features for arcpy in the future!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64434#M5266</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-10T22:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64435#M5267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ah, thank you Chris, you got me thinking about performance of the display refresh - this can be a subtlety greatly impacting performance.&amp;nbsp; So what I needed access to was PartialRefresh (IActiveView)... I was banging my head against this for awhile, and had to go back to the basics to understand w/ VBA.&amp;nbsp; So this VBA code more precisely mimics the 'Clear Selected Features' button (without redrawing everything):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
Dim pMxDocument As IMxDocument
Dim pMap As IMap
Dim pActiveView As IActiveView

Set pMxDocument = ThisDocument
Set pMap = pMxDocument.FocusMap
Set pActiveView = pMap

pActiveView.PartialRefresh esriViewGeoSelection, Nothing, Nothing
pMap.ClearSelection
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;So, with that, I pared down my comtypes code to do essentially the same thing (please bear in mind, I'm still learning to apply this thing called comtypes):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import Snippets
import comtypes.gen.esriArcMapUI as esriArcMapUI
import comtypes.gen.esriCarto as esriCarto

pApp = Snippets.GetApp()
pDoc = pApp.Document
pMxDoc = Snippets.CType(pDoc, esriArcMapUI.IMxDocument)
pMap = pMxDoc.FocusMap
pAV = Snippets.CType(pMap, esriCarto.IActiveView)

pAV.PartialRefresh(esriCarto.esriViewGeoSelection, None, None)
pMap.ClearSelection()
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 1st time running in ArcMap, it takes a moment to load but nothing really limiting, and successive executions...uh, greased lightning (pardon the pun).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;One more thing I may have omitted... since the script has been pared down, I admit I am not sure yet about what the comtypes is doing in the GetModule function, but it's getting called from the facilitating Snippets.py (also called GetModule) with:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;from comtypes.client import GetModule&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It has to do with getting the COM library refs...I think the 2 code lines below 'bypass' Snippets to get specifically to the interfaces needed (IActiveView and IMxDocument):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;import comtypes.gen.esriArcMapUI as esriArcMapUI&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import comtypes.gen.esriCarto as esriCarto&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Not sure I fully understand that just yet - anyway, if I cut out too much in the 'initialization', you can make the Snippet.GetModule call to build what you need....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64435#M5267</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-10T22:28:41Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64436#M5268</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;...quick update about the comtypes installation - the above previous testing was with 10.0, which the companion module Snippets.py was designed to run with; I also have a 10.1 server installation where I installed comtypes (same version) today and got that running successfully, although haven't fully tested it yet.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;However, I'll have to update Snippets if I intend to use it...I have both ArcServer and Desktop running on Windows Server 2012 and apparently the registry keys are different - the GetLibPath function that uses the python _winreg module does not find the HKEY_CLASSES_ROOT with the provided TypeLib key {866AE5D3-530C-11D2-A2BD-0000F8774FB5}....&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; import _winreg
&amp;gt;&amp;gt;&amp;gt; keyESRI = _winreg.OpenKey(_winreg.HKEY_CLASSES_ROOT, \
...&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r"TypeLib\{866AE5D3-530C-11D2-A2BD-0000F8774FB5}\a.0\HELPDIR")

Traceback (most recent call last):
&amp;nbsp; File "&amp;lt;stdin&amp;gt;", line 2, in &amp;lt;module&amp;gt;
WindowsError: [Error 2] The system cannot find the file specified
&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; 
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That function just makes it more universal to find the root COM directory -- so for now I 'hardwired' it in this fashion (bypassing Snippets until I can get it fixed):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; from comtypes.client import GetModule
&amp;gt;&amp;gt;&amp;gt; GetModule(r'C:\Program Files (x86)\ArcGIS\Desktop10.1\com\esriArcMapUI.olb')
# Generating comtypes.gen._40499F24_596F_45D2_ACE1_A251E2990017_0_10_1
# Generating comtypes.gen._00020430_0000_0000_C000_000000000046_0_2_0
# Generating comtypes.gen.stdole
# Generating comtypes.gen._866AE5D3_530C_11D2_A2BD_0000F8774FB5_0_10_1
# Generating comtypes.gen._59FCCD31_434C_4017_BDEF_DB4B7EDC9CE0_0_10_1
# Generating comtypes.gen._C4B094C2_FF32_4FA1_ABCB_7820F8D6FB68_0_10_1
# Generating comtypes.gen._5E1F7BC3_67C5_4AEE_8EC6_C4B73AAC42ED_0_10_1
# Generating comtypes.gen.esriSystem
# Generating comtypes.gen.esriGeometry
# Generating comtypes.gen._4ECCA6E2_B16B_4ACA_BD17_E74CAE4C150A_0_10_1
# Generating comtypes.gen.esriSystemUI
# Generating comtypes.gen.esriDisplay
# Generating comtypes.gen.esriFramework
# Generating comtypes.gen._4A9C9ED7_F7DB_4614_B480_A5D265C961FC_0_10_1
# Generating comtypes.gen._0475BDB1_E5B2_4CA2_9127_B4B1683E70C2_0_10_1
# Generating comtypes.gen._18F2FC71_6B30_45B9_B101_037A8B868B66_0_10_1
...
...
...
(etc.)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If I'm using the correct terminology, the GetModule function makes a one-time call to create the 'wrapper' output to the Python install location for site pkgs, in this case comtypes makes a gen output folder (e.g., C:\Python27\ArcGIS10.1\Lib\site-packages\comtypes\gen).&amp;nbsp; That's what I was referring to in my last post about 'if you need it call the GetModule function' and the output gen will be built - on successive calls the olb has already been 'wrapped', and you just need to do something like this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import comtypes.gen.esriArcMapUI as esriArcMapUI
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;...and, since having problems with the Snippet helper module, until that's fixed the comtypes CreateObject method can be called directly, for example to get the current ArcMap app (only 1 ArcGIS app was running at the time):&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
&amp;gt;&amp;gt;&amp;gt; pAppROT = comtypes.client.CreateObject(esriFramework.AppROT, interface=esriFramework.IAppROT)
&amp;gt;&amp;gt;&amp;gt; pAppROT.count
1

&amp;gt;&amp;gt;&amp;gt; pApp = pAppROT.Item(0)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Hope this clarifies a little how Snippets facilitates comtypes.&amp;nbsp; Maybe I haven't looked hard enough yet, but if someone knows the registry key fix for the GetLibPath function at 10.1 (Windows Server 2012), please let me know... I appreciate it.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;EDIT:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ah, looks like Luke has posted a modified GetLibPath function here he calls a 'kludge' but looks promising to me - I will test this tomorrow:&lt;/SPAN&gt;&lt;BR /&gt;&lt;A href="http://gis.stackexchange.com/questions/50714/are-there-any-python-scripts-for-creating-mxd-files/50718#50718" rel="nofollow noopener noreferrer" target="_blank"&gt;http://gis.stackexchange.com/questions/50714/are-there-any-python-scripts-for-creating-mxd-files/50718#50718&lt;/A&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 10 Dec 2021 22:28:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64436#M5268</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2021-12-10T22:28:43Z</dc:date>
    </item>
    <item>
      <title>Re: Use Arcpy to Unselect the currently selected Features in all layers</title>
      <link>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64437#M5269</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I find this confusion over what seem to be various flavors of 'Layer' objects.&amp;nbsp; Once you get arcpy to hand you a layer object from ListLayers and you loop through them, try using the name property of the lyr instead of the layer object itself. E.g.:&lt;/P&gt;&lt;P&gt;this seems to work for me:&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #000000; background-color: #f6f6f6; font-family: 'courier new', courier, monospace;"&gt;arcpy.SelectLayerByAttribute_management(lyr.name,&amp;nbsp;"CLEAR_SELECTION")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;And, as many others note, this is really slow. And if going to ArcObjects is not in your game, there is a python code through arcpy that clears selections really fast:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier, monospace;"&gt;lyr.setSelectionSet("NEW",[])&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6; color: #3d3d3d;"&gt;Note: this is calling a method of the layer object, it is not an arcpy function.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="background-color: #f6f6f6; color: #3d3d3d;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Oct 2017 19:05:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/use-arcpy-to-unselect-the-currently-selected/m-p/64437#M5269</guid>
      <dc:creator>GeorgeRiner</dc:creator>
      <dc:date>2017-10-05T19:05:56Z</dc:date>
    </item>
  </channel>
</rss>

