<?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 check for selected features in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655328#M51024</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I trying to create an arcpy script that will run only if there are selected features in a layer, however I can't figure out how to get arcpy to test for selected features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've read posts about using GetCount, however this seems to only work if there is a difference in the number of selected features to the full feature count of the layer.&amp;nbsp; I want my script to run even if EVERY feature in the layer is selected (but ONLY if features are selected).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way I can do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 03 Jan 2013 17:13:25 GMT</pubDate>
    <dc:creator>MikeLouwrens</dc:creator>
    <dc:date>2013-01-03T17:13:25Z</dc:date>
    <item>
      <title>check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655328#M51024</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hi,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I trying to create an arcpy script that will run only if there are selected features in a layer, however I can't figure out how to get arcpy to test for selected features.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I've read posts about using GetCount, however this seems to only work if there is a difference in the number of selected features to the full feature count of the layer.&amp;nbsp; I want my script to run even if EVERY feature in the layer is selected (but ONLY if features are selected).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way I can do this?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 17:13:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655328#M51024</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2013-01-03T17:13:25Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655329#M51025</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I would think that you could get an initial count and assign as say numRecords then run a selection and set another get count as selRecords. then check if the selected count is null&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 17:26:15 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655329#M51025</guid>
      <dc:creator>CarlSunderman</dc:creator>
      <dc:date>2013-01-03T17:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655330#M51026</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Hi,&lt;BR /&gt;&lt;BR /&gt;I trying to create an arcpy script that will run only if there are selected features in a layer, however I can't figure out how to get arcpy to test for selected features.&lt;BR /&gt;&lt;BR /&gt;I've read posts about using GetCount, however this seems to only work if there is a difference in the number of selected features to the full feature count of the layer.&amp;nbsp; I want my script to run even if EVERY feature in the layer is selected (but ONLY if features are selected).&lt;BR /&gt;&lt;BR /&gt;Is there a way I can do this?&lt;BR /&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;Mike.&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;Yes, there are many ways to do this, here is one:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
result = int(arcpy.GetCount_management(Parcels).getOutput(0))
if result:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'No selected features'
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:45:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655330#M51026</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2021-12-12T03:45:18Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655331#M51027</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Yes, there are many ways to do this, here is one:&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
result = int(arcpy.GetCount_management(Parcels).getOutput(0))
if result:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # do something
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print 'No selected features'
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt;This returns a true result even if I haven't selected anything.&amp;nbsp; This only returns a false result if I run a selection and nothing is selected...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:45:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655331#M51027</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2021-12-12T03:45:20Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655332#M51028</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Layer Describe properties has an FIDSet property which returns a semicolon-delimited string of selected feature IDs. If the string is empty no features are selected:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;desc = arcpy.Describe(lyr) if not desc.FIDSet&amp;nbsp; == '': &amp;nbsp;&amp;nbsp; print 'Layer has a selection'&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 03 Jan 2013 17:45:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655332#M51028</guid>
      <dc:creator>ChrisFox3</dc:creator>
      <dc:date>2013-01-03T17:45:16Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655333#M51029</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I would think that you could get an initial count and assign as say numRecords then run a selection and set another get count as selRecords. then check if the selected count is null&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;&lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;this is what I have done - I ran a selection on objectid = 1000000000000 (a feature that should never exist...) then my getcount will return 0 if nothing else selected, or the number of selected features if other features are already selected.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;arcpy.SelectLayerByAttribute_management(layer.name,"ADD_TO_SELECTION",'"OBJECTID" = 1000000000000')

featurecount = int(arcpy.GetCount_management(layer.name).getOutput(0))


if featurecount &amp;gt; 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; #Do Something
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SelectLayerByAttribute_management(layer.name, "CLEAR_SELECTION")&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;This seems to work &lt;span class="lia-unicode-emoji" title=":grinning_face_with_smiling_eyes:"&gt;😄&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="color: black; font-family: Consolas;"&gt;&lt;BR /&gt;Cheers,&lt;BR /&gt;&lt;/SPAN&gt;&lt;SPAN style="color: black; font-family: Consolas;"&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:45:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655333#M51029</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2021-12-12T03:45:23Z</dc:date>
    </item>
    <item>
      <title>Re: check for selected features</title>
      <link>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655334#M51030</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;Layer Describe properties has an FIDSet property which returns a semicolon-delimited string of selected feature IDs. If the string is empty no features are selected:&lt;BR /&gt; &lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
desc = arcpy.Describe(lyr)
if not desc.FIDSet&amp;nbsp; == '':
&amp;nbsp;&amp;nbsp; print 'Layer has a selection'
&lt;/PRE&gt;&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;oh! that works too.&amp;nbsp; thanks for that &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cheers,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 03:45:25 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-for-selected-features/m-p/655334#M51030</guid>
      <dc:creator>MikeLouwrens</dc:creator>
      <dc:date>2021-12-12T03:45:25Z</dc:date>
    </item>
  </channel>
</rss>

