<?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: How to determine if Select By Location returns nothing in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662690#M51493</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think arcpy.GetCount_management(&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;&lt;SPAN&gt;) ought to do the trick. Just be careful - to actually use it you need to do something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you can use a conditional to check for change after the selection (if the selection doesn't actually select anything, the count won't change), i.e.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;initialCount = int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))
# do selection on &lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;
selectedCount = int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))
if initialCount != selectedCount:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # do stuff
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # no selection, don't do stuff&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how you get on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 04:01:13 GMT</pubDate>
    <dc:creator>StacyRendall1</dc:creator>
    <dc:date>2021-12-12T04:01:13Z</dc:date>
    <item>
      <title>How to determine if Select By Location returns nothing</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662689#M51492</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Windows XP Pro SP3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ArcView 10.0 SP2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Python 2.6&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I want to do a basic field population by looping through a source polygon feature layer and selecting all target features from the target feature layer that are completely within the current polygon. If the selection returns nothing then I want to do nothing, otherwise I'll do a calculate on the target layer. If I'm not mistaken if I perform a field calculation on a layer with nothing selected, then all features get calculated, right? I really don't want to do that. Any ideas? Thanks!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 20 Feb 2012 20:47:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662689#M51492</guid>
      <dc:creator>GlennKammerer</dc:creator>
      <dc:date>2012-02-20T20:47:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if Select By Location returns nothing</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662690#M51493</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I think arcpy.GetCount_management(&lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;&lt;SPAN&gt;) ought to do the trick. Just be careful - to actually use it you need to do something like:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Then you can use a conditional to check for change after the selection (if the selection doesn't actually select anything, the count won't change), i.e.:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;initialCount = int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))
# do selection on &lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;
selectedCount = int(arcpy.GetCount_management(&lt;SPAN style="font-style:italic;"&gt;featureClass&lt;/SPAN&gt;).getOutput(0))
if initialCount != selectedCount:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # do stuff
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # no selection, don't do stuff&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Let me know how you get on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Stacy&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 04:01:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662690#M51493</guid>
      <dc:creator>StacyRendall1</dc:creator>
      <dc:date>2021-12-12T04:01:13Z</dc:date>
    </item>
    <item>
      <title>Re: How to determine if Select By Location returns nothing</title>
      <link>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662691#M51494</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Stacy, worked like a charm!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 18:50:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/how-to-determine-if-select-by-location-returns/m-p/662691#M51494</guid>
      <dc:creator>GlennKammerer</dc:creator>
      <dc:date>2012-02-21T18:50:11Z</dc:date>
    </item>
  </channel>
</rss>

