<?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: Check if FeaturLayer has Selection FAIL in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98131#M3386</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Logan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's the ticket! It's not on the object model diagram. Thanks for the heads up&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 02 Nov 2010 18:44:42 GMT</pubDate>
    <dc:creator>GregCorradini</dc:creator>
    <dc:date>2010-11-02T18:44:42Z</dc:date>
    <item>
      <title>Check if FeaturLayer has Selection FAIL</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98128#M3383</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm trying to find a FeatureLayer property or function that returns the number of features selected after I run a gp.SelectLayerByAttribute() or gp.SelectLayerByLocation() using the Python geoprocessing API. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This should be a simple thing to achieve (It should be!) with the geoprocessing API (like it is with C# ArcObjects API). But now I'm starting to wonder if there's not an easy way to do this after reading the geoprocessing object model diagram. Hopefully someone can show me the light and where I've strayed.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I was hoping that the selection functions would return an integer giving feedback on what just happened (like 0 for nothing was selected would be useful). Instead they just return the name of the layer even when I know I'm selecting something that doesn't exist in the Layer. Then I thought the Layer or Describe object would have a .HasSelected property somewhere. Nope. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;If nothing exists, then the one known laborious/ridiculous workaround to test if something was selected would be as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) run a SelectLayerByAttribute or SelectLayerByLocation on a Layer &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2) take that Layer (hopefully with a selection) and create a new Layer with gp.MakeFeatureLayer(). The goal here being to create a temp layer with our selected feature&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;3) put a SearchCursor() on the temp Layer and run through it to see if there are any rows that are not None types. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Ideas? I'm using ArcGIS 9.3.1&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Nov 2010 17:58:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98128#M3383</guid>
      <dc:creator>GregCorradini</dc:creator>
      <dc:date>2010-11-02T17:58:00Z</dc:date>
    </item>
    <item>
      <title>Re: Check if FeaturLayer has Selection FAIL</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98129#M3384</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;result = gp.GetCount_management(featureLayer)
count = int(result)&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:08:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98129#M3384</guid>
      <dc:creator>LoganPugh</dc:creator>
      <dc:date>2021-12-11T06:08:08Z</dc:date>
    </item>
    <item>
      <title>Re: Check if FeaturLayer has Selection FAIL</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98130#M3385</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Or even:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;if int(gp.GetCount_management(featureLayer).getoutput(0)) &amp;gt; 0:
&amp;nbsp;&amp;nbsp; do this
else:
&amp;nbsp;&amp;nbsp; do that&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sometimes it's usefull to compare the selection count with the total count:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
if int(gp.GetCount_management(gp.describe(featureLayer).catalogpath).getoutput(0)) &amp;gt; int(gp.GetCount_management(featureLayer).getoutput(0)):
&amp;nbsp;&amp;nbsp; do this
else:
&amp;nbsp;&amp;nbsp; do that&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;And then its sometimes usefull to get the OBJECTIDs of the selected features (BTW there has to be a selection in the featurelayer not just a SQL definition):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;selectedOidList = [int(oid) for oid in gp.describe(featureLayer).fidset.split(";")]&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:08:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98130#M3385</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T06:08:11Z</dc:date>
    </item>
    <item>
      <title>Re: Check if FeaturLayer has Selection FAIL</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98131#M3386</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks Logan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;That's the ticket! It's not on the object model diagram. Thanks for the heads up&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 02 Nov 2010 18:44:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/check-if-featurlayer-has-selection-fail/m-p/98131#M3386</guid>
      <dc:creator>GregCorradini</dc:creator>
      <dc:date>2010-11-02T18:44:42Z</dc:date>
    </item>
  </channel>
</rss>

