Clear Selected Features in All layers

5022
6
Jump to solution
04-11-2013 10:24 AM
TimWitt
Frequent Contributor
I am looking for a way with python to clear all selected features in my dataframe. Like the "Clear Selected Features" button in ArcMap.

I have been looking for this online and just could not find it.

The only thing I can find is SelectLayerByAttribute_management(in_layer_or_view,"CLEAR_SELECTION")
The problem there is, that I need to feed it a specific layer, but I want to clear the selection in every layer.

Anyone know the answer?
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
ChristopherBlinn1
Occasional Contributor III
Have you tried looping through your layers in your dataframe?

for lyr in arcpy.mapping.ListLayers(mxd,"",df):   SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")


That should take each layer in your dataframe and clear any selected features.

Hope this helps!

Best,
Chris B.

View solution in original post

0 Kudos
6 Replies
ChristopherBlinn1
Occasional Contributor III
Have you tried looping through your layers in your dataframe?

for lyr in arcpy.mapping.ListLayers(mxd,"",df):   SelectLayerByAttribute_management(lyr,"CLEAR_SELECTION")


That should take each layer in your dataframe and clear any selected features.

Hope this helps!

Best,
Chris B.
0 Kudos
TimWitt
Frequent Contributor
Thanks,

It works, but it slows  down my script a lot since I have 40 layers in my mxd.

I was just surprised I couldn't find anything, since there is a button that clears everything.
0 Kudos
MathewCoyle
Frequent Contributor
there is a button that clears everything.


That is available through ArcObjects, not arcpy.
http://forums.esri.com/Thread.asp?c=93&f=992&t=274217
0 Kudos
TimWitt
Frequent Contributor
That is available through ArcObjects, not arcpy.
http://forums.esri.com/Thread.asp?c=93&f=992&t=274217



But is there anyway to achieve the same in arcpy?
0 Kudos
MathewCoyle
Frequent Contributor
But is there anyway to achieve the same in arcpy?


Yes... Christopher's answer.
0 Kudos
PhilLarkin1
Occasional Contributor III

Pro solution:

aprx = arcpy.mp.ArcGISProject("CURRENT")
map = aprx.listMaps('Your Map')[0]
map.clearSelection()


Map—ArcGIS Pro | Documentation

 

0 Kudos