<?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:  Make sure there's selection before execute 'Copy Features&amp;quot; in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97460#M7558</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And something like this should also work:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;selection = arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause="Field = 'Something'")

result = arcpy.GetCount_management(selection)
count = int(result.getOutput(0))
if count:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print count
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures.......
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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;See: &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/get-count.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Get Count&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could use GetCount to count items in the layer before and after the selection and if selection is less than the original count and greater than zero then do the copy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:06:42 GMT</pubDate>
    <dc:creator>RandyBurton</dc:creator>
    <dc:date>2021-12-11T06:06:42Z</dc:date>
    <item>
      <title>Arcpy:  Make sure there's selection before execute 'Copy Features"</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97458#M7556</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;I use "Copy Features" tool to make a layer from selection.&amp;nbsp; It's crucial that I check&amp;nbsp;for a selection first or it will copy the whole layer.&amp;nbsp; Please help me with that.&amp;nbsp; Thank you!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 31 Aug 2018 23:19:26 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97458#M7556</guid>
      <dc:creator>helenchu</dc:creator>
      <dc:date>2018-08-31T23:19:26Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy:  Make sure there's selection before execute 'Copy Features"</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97459#M7557</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;for map and pro&lt;/P&gt;&lt;P&gt;&lt;A class="link-titled" href="http://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm" title="http://pro.arcgis.com/en/pro-app/arcpy/mapping/layer-class.htm"&gt;Layer—ArcPy | ArcGIS Desktop&lt;/A&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE style="background-color: #ffffff; border-collapse: collapse; border-image-outset: 0; border-image-repeat: stretch; border-image-slice: 100%; border-image-source: none; border-image-width: 1; border-spacing: 0px 0px; color: #4c4c4c; font-family: &amp;amp;quot; avenir next w01&amp;amp;quot;,&amp;amp;quot;avenir next w00&amp;amp;quot;,&amp;amp;quot;avenir next&amp;amp;quot;,&amp;amp;quot;avenir&amp;amp;quot;,&amp;amp;quot;helvetica neue&amp;amp;quot;,sans-serif; font-size: 14.8px; font-style: normal; font-variant: normal; font-weight: 400; letter-spacing: normal; line-height: 26.35px; margin-bottom: 26.35px; orphans: 2; overflow: auto; text-align: left; text-decoration: none; text-indent: 0px; text-transform: none; -webkit-text-stroke-width: 0px; white-space: normal; width: 768.41px; word-spacing: 0px; border: 0.5px solid #cccccc;"&gt;&lt;TBODY style="overflow: auto; width: 100%;"&gt;&lt;TR style="border-bottom-color: #cccccc; border-bottom-style: solid; border-bottom-width: 1px; text-align: left;"&gt;&lt;TD style="border-left-color: #cccccc; border-left-style: solid; border-left-width: 1px; border-right-color: #cccccc; border-right-style: solid; border-right-width: 1px; font-weight: 300; padding: 8.67px;"&gt;getSelectionSet ()&lt;/TD&gt;&lt;TD style="border-left-color: #cccccc; border-left-style: solid; border-left-width: 1px; border-right-color: #cccccc; border-right-style: solid; border-right-width: 1px; font-weight: 300; padding: 8.67px;"&gt;&lt;P style="margin-bottom: 0px; margin-top: 0px;"&gt;Returns a layer's selection as a Python set of object IDs.&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;which will be &amp;gt; 0 if there is a selection.&lt;/P&gt;&lt;P&gt;If you don't have a layer, then use MakeFeatureLayer first then delete if needed&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 01 Sep 2018 00:29:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97459#M7557</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2018-09-01T00:29:19Z</dc:date>
    </item>
    <item>
      <title>Re: Arcpy:  Make sure there's selection before execute 'Copy Features"</title>
      <link>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97460#M7558</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;And something like this should also work:&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;selection = arcpy.SelectLayerByAttribute_management(layer, "NEW_SELECTION",
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; where_clause="Field = 'Something'")

result = arcpy.GetCount_management(selection)
count = int(result.getOutput(0))
if count:
&amp;nbsp;&amp;nbsp;&amp;nbsp; print count
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.CopyFeatures.......
‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍&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;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&gt;&lt;SPAN&gt;‍&lt;/SPAN&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;See: &lt;A href="http://desktop.arcgis.com/en/arcmap/latest/tools/data-management-toolbox/get-count.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;Get Count&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;You could use GetCount to count items in the layer before and after the selection and if selection is less than the original count and greater than zero then do the copy.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:06:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/arcpy-make-sure-there-s-selection-before-execute/m-p/97460#M7558</guid>
      <dc:creator>RandyBurton</dc:creator>
      <dc:date>2021-12-11T06:06:42Z</dc:date>
    </item>
  </channel>
</rss>

