<?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: arcpy.da.searchcursor with nothing selected returns all records in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-with-nothing-selected/m-p/534679#M41885</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Before opening the search cursor, could you &lt;A href="http://blog.technicallyliving.com/2013/08/arcpy-testing-for-selected-features/" rel="nofollow noopener noreferrer" target="_blank"&gt;check to see if any features are selected&lt;/A&gt;? If there are selected features, continue to use search cursor; If not, handle exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming it is a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018v/018v00000066000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;layer&lt;/A&gt;, here's the direction I would go.&lt;/P&gt;&lt;P&gt;I have not tested this. You may have to check for a length like &lt;SPAN style="font-family: 'courier new', courier;"&gt;len(desc.FIDSet) &amp;gt; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;desc = arcpy.Describe(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;manhole_layer&lt;/SPAN&gt;)
if desc.FIDSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Do something with selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(manhole_layer, "*") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Handle Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No features selected."&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 23:13:47 GMT</pubDate>
    <dc:creator>BlakeTerhune</dc:creator>
    <dc:date>2021-12-11T23:13:47Z</dc:date>
    <item>
      <title>arcpy.da.searchcursor with nothing selected returns all records</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-with-nothing-selected/m-p/534678#M41884</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I am trying to loop thru selected features using the da.SearchCursor statement below.&amp;nbsp; It works when the users selects something.&amp;nbsp; When there are no points or lines selected it returns the whole layer.&amp;nbsp; Should I be using another function? &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(manhole_layer,"*") as cursor:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 27 Jan 2015 21:52:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-with-nothing-selected/m-p/534678#M41884</guid>
      <dc:creator>BrianBolduc</dc:creator>
      <dc:date>2015-01-27T21:52:52Z</dc:date>
    </item>
    <item>
      <title>Re: arcpy.da.searchcursor with nothing selected returns all records</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-with-nothing-selected/m-p/534679#M41885</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Before opening the search cursor, could you &lt;A href="http://blog.technicallyliving.com/2013/08/arcpy-testing-for-selected-features/" rel="nofollow noopener noreferrer" target="_blank"&gt;check to see if any features are selected&lt;/A&gt;? If there are selected features, continue to use search cursor; If not, handle exception.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Assuming it is a &lt;A href="http://resources.arcgis.com/en/help/main/10.2/018v/018v00000066000000.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;layer&lt;/A&gt;, here's the direction I would go.&lt;/P&gt;&lt;P&gt;I have not tested this. You may have to check for a length like &lt;SPAN style="font-family: 'courier new', courier;"&gt;len(desc.FIDSet) &amp;gt; 0&lt;/SPAN&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;desc = arcpy.Describe(&lt;SPAN style="color: rgba(0, 0, 0, 0); font-family: Consolas, 'Courier New', Courier, mono, serif; font-size: 12px;"&gt;manhole_layer&lt;/SPAN&gt;)
if desc.FIDSet:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Do something with selection
&amp;nbsp;&amp;nbsp;&amp;nbsp; with arcpy.da.SearchCursor(manhole_layer, "*") as cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print row
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; # Handle Exception
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "No features selected."&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 23:13:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-da-searchcursor-with-nothing-selected/m-p/534679#M41885</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2021-12-11T23:13:47Z</dc:date>
    </item>
  </channel>
</rss>

