<?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: Get Count Equal Zero in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108711#M8402</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at the FIDset in&amp;nbsp;&lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-functions/layer-properties.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Describe&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;lyrs_NET &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"*_NET"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lay &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; lyrs_NET&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; selCount &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fid&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fid &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Describe&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lay&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fidset&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;";"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; fid &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If selCount ==0, no selection.&amp;nbsp; Otherwise, selCount is equal to the number of items selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:33:22 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2021-12-11T06:33:22Z</dc:date>
    <item>
      <title>Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108709#M8400</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am wanting to execute a simple piece of Python code. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If selected features is one or more --&amp;gt; copy selected features to a predefined&amp;nbsp;geodatabase&lt;/P&gt;&lt;P&gt;Else Print "No Features Selected"&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But I am finding the GetCount selects all features within a featureclass when there is none pre-selected. How do I do this in Python? I am running the script from within ArcMap so the selected features within the data view window is processed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Example script below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;# Import arcpy module&lt;BR /&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;import sys&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;arcpy.SetProgressorLabel("Processing Annotation Owner Layer")&lt;BR /&gt;arcpy.MakeFeatureLayer_management(r"Annotation\AnnotationOwner", "Layer")&lt;BR /&gt;selCountResult = arcpy.GetCount_management("Layer")&lt;BR /&gt;selCount = int(selCountResult.getOutput(0))&lt;BR /&gt;arcpy.AddMessage ("{0} Features Selected from Annotation Owner Layer".format(str(selCount)))&lt;BR /&gt;if selCount &amp;gt; 0:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(r"Annotation\Maritime.DBO.AnnotationMisc", os.path.join(GDBName, "AnnotationMisc"))&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage ("{0} Features Copied From Annotation Owner Layer".format(str(selCount)))&lt;BR /&gt;else:&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Nothing Copied from Annotation Owner Layer")&lt;BR /&gt;arcpy.Delete_management("Layer","")&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 09:08:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108709#M8400</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2017-07-19T09:08:00Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108710#M8401</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;First of all the&amp;nbsp;&lt;SPAN style="background-color: #ffffff;"&gt;arcpy.GetCount_management tool will count the selected features in a table if you have a selection or return the total number of features in case you don't have a selection.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are two reasons that I can think of. The first would be to check if you have an output extent defined in the geoprocessing environment settings:&amp;nbsp;&lt;/P&gt;&lt;BLOCKQUOTE class="jive_macro_quote jive-quote jive_text_macro"&gt;&lt;EM&gt;This tool honors the Output Extent environment. Only those features that are within or intersect the Output Extent environment setting will be counted.&lt;/EM&gt;&lt;/BLOCKQUOTE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The other aspect is related to using annotations. However, I just did a test with a selection of feature-linked annotation and the the GetCount tools returns the correct result.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 13:07:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108710#M8401</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2017-07-19T13:07:35Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108711#M8402</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Take a look at the FIDset in&amp;nbsp;&lt;A href="http://desktop.arcgis.com/en/arcmap/10.3/analyze/arcpy-functions/layer-properties.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Describe&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;lyrs_NET &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;mapping&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;ListLayers&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;mxd&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;"*_NET"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;,&lt;/SPAN&gt; df&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; lay &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; lyrs_NET&lt;SPAN class="punctuation token"&gt;:&lt;/SPAN&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; selCount &lt;SPAN class="operator token"&gt;=&lt;/SPAN&gt; len&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;[&lt;/SPAN&gt;int&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;fid&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;for&lt;/SPAN&gt; fid &lt;SPAN class="keyword token"&gt;in&lt;/SPAN&gt; arcpy&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;Describe&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;lay&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;fidset&lt;SPAN class="punctuation token"&gt;.&lt;/SPAN&gt;split&lt;SPAN class="punctuation token"&gt;(&lt;/SPAN&gt;&lt;SPAN class="string token"&gt;";"&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt; &lt;SPAN class="keyword token"&gt;if&lt;/SPAN&gt; fid &lt;SPAN class="operator token"&gt;!=&lt;/SPAN&gt; &lt;SPAN class="string token"&gt;''&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;]&lt;/SPAN&gt;&lt;SPAN class="punctuation token"&gt;)&lt;/SPAN&gt;‍‍&lt;SPAN class="line-numbers-rows"&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If selCount ==0, no selection.&amp;nbsp; Otherwise, selCount is equal to the number of items selected.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:33:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108711#M8402</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2021-12-11T06:33:22Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108712#M8403</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;In addition to the other responses, which are both helpful comments, you can use &lt;SPAN style="color: #4d4d4d; font-family: 'Lucida Grande', 'Segoe UI', Arial, sans-serif; font-size: 14px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: #ffffff; text-decoration-style: initial; text-decoration-color: initial; display: inline !important; float: none;"&gt;getSelectionSet ()&lt;/SPAN&gt; from &lt;A class="link-titled" href="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm" title="http://desktop.arcgis.com/en/arcmap/latest/analyze/arcpy-mapping/layer-class.htm"&gt;Layer—Help | ArcGIS Desktop&lt;/A&gt;&amp;nbsp; to determine selected records of a layer.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 16:53:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108712#M8403</guid>
      <dc:creator>JoshuaBixby</dc:creator>
      <dc:date>2017-07-19T16:53:38Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108713#M8404</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Apparently, this was added at 10.3.&amp;nbsp; We are still on the Utilities/Telecom model (10.2.1), and doesn't seem to be available.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Something to look forward to &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/happy.png" /&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 19 Jul 2017 17:01:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108713#M8404</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2017-07-19T17:01:32Z</dc:date>
    </item>
    <item>
      <title>Re: Get Count Equal Zero</title>
      <link>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108714#M8405</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;As the GetCount gets all records when none are preselected I looked to achieve this a different way. I looked into the getSelectionSet() option but couldn't understand how it works. I successfully used the FIDSet in arcpy.Describe to get my script to work how I want. Below is of my script. I run this script from within ArcMap so selected features can be processed.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 12px;"&gt;arcpy.MakeFeatureLayer_management(r"Annotation\Maritime.DBO.AnnotationMisc", "Layer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;desc = arcpy.Describe("Layer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;desc.FIDSet&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;if desc.FIDSet &amp;lt;&amp;gt; "":&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; selCountResult = arcpy.GetCount_management("Layer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; selCount = int(selCountResult.getOutput(0))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage ("{0} Features Selected from Annotation Misc Layer".format(str(selCount)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures_management(r"Annotation\Maritime.DBO.AnnotationMisc", os.path.join(GDBName, "AnnotationMisc"))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage ("{0} Features Copied From Annotationn Misc Layer".format(str(selCount)))&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Nothing Selected from Annotation Misc Layer")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN style="font-size: 12px;"&gt;arcpy.Delete_management("Layer","")&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jul 2017 01:20:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/get-count-equal-zero/m-p/108714#M8405</guid>
      <dc:creator>DaveMarkey</dc:creator>
      <dc:date>2017-07-27T01:20:53Z</dc:date>
    </item>
  </channel>
</rss>

