<?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 any features are selected in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492972#M38658</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; I tried switching selections, but that raised an error on SelectLayerByAttribute - module has no attribute&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was my bad. Still getting used to arcpy syntax, which if you don't import the managment module requires you to specify it: SelectLayerByAttribute&lt;/SPAN&gt;&lt;STRONG&gt;_management&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I repaired the code sample above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 05 Apr 2012 14:14:24 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2012-04-05T14:14:24Z</dc:date>
    <item>
      <title>Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492968#M38654</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I want to check if any features in a feature class are selected, and exit the script with a message to the user if they aren't. But I can't find a function that checks &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;if&lt;/SPAN&gt;&lt;SPAN&gt; any features are selected. The code below gives a count of selected features, if any are, but it also returns a count of all features (~27k+) if none are. This defeats the purpose of the if statement. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Is there a way to just check if any are selected - a HasSelected type of property? Thanks.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# check how many parcels are selected &amp;nbsp;&amp;nbsp;&amp;nbsp; count = int(arcpy.GetCount_management("Parcel").getOutput(0)) # returns count of all parcels if none selected. This makes if statement always true, regardless if any parcels are selected&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; # if no parcels are selected, inform user and exit script &amp;nbsp;&amp;nbsp;&amp;nbsp; if count &amp;lt; 1: &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("No features selected! \n Please select at least one parcel feature. \n") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Quitting the Create Case tool \n") &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sys.exit("Goodbye! Try again!")&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Apr 2012 18:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492968#M38654</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2012-04-04T18:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492969#M38655</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The arcpy &lt;/SPAN&gt;&lt;A class="jive-link-external-small" href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Layer_properties/000v0000002t000000/" rel="nofollow" target="_blank"&gt;Layer &lt;/A&gt;&lt;SPAN&gt;object has a property called FIDSet that is "A semicolon-delimited string of selected feature IDs (record numbers)." So, you should be able to test against that to either count selected or determine if any features are selected.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 04 Apr 2012 19:05:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492969#M38655</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2012-04-04T19:05:12Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492970#M38656</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I want to check if any features in a feature class are selected, and exit the script with a message to the user if they aren't. &lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I think a good approach to try would be to switch the selection. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN style="font-style:italic;"&gt;UPDATE: code repaired to add "_management" to tool call, see post below&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# check how many parcels are selected
count1 = int(arcpy.GetCount_management("Parcel").getOutput(0)) 
arcpy.SelectLayerByAttribute_management("Parcel","SWITCH_SELECTION") # switch selection
count2 = int(arcpy.GetCount_management("Parcel").getOutput(0)) 
arcpy.SelectLayerByAttribute_management("Parcel","SWITCH_SELECTION") # switch it back 
# if no parcels are selected, inform user and exit script
if count1 == 0 or count2 == 0:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("No features selected! \n Please select at least one parcel feature. \n")
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddError("Quitting the Create Case tool \n")
else:
&amp;nbsp;&amp;nbsp;&amp;nbsp; ....
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 21:41:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492970#M38656</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T21:41:44Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492971#M38657</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, the FIDSet worked. I tried switching selections, but that raised an error on SelectLayerByAttribute - module has no attribute, and although it seems like it would be necessary to select an attribute, I don't see where it's required for that function in &lt;/SPAN&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000071000000"&gt;help&lt;/A&gt;&lt;SPAN&gt;. &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Anyway, thanks for the help, I really appreciate it. I'm trying to idiot-proof the script, and feel very qualified to test that.&amp;nbsp; I have another question as to why GetParameterAsText retrieves the value entered ok, but will strip off all characters before a final "-" when I use CalculateField to set the field value, but I'll post that in another thread if I can't figure it out.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 14:07:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492971#M38657</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2012-04-05T14:07:34Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492972#M38658</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt; I tried switching selections, but that raised an error on SelectLayerByAttribute - module has no attribute&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This was my bad. Still getting used to arcpy syntax, which if you don't import the managment module requires you to specify it: SelectLayerByAttribute&lt;/SPAN&gt;&lt;STRONG&gt;_management&lt;/STRONG&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I repaired the code sample above.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 14:14:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492972#M38658</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2012-04-05T14:14:24Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492973#M38659</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks, I'll try that. Surprised I didn't see it myself. Maybe I should actually look before I just copy &amp;amp; paste... &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Apr 2012 16:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/492973#M38659</guid>
      <dc:creator>Zeke</dc:creator>
      <dc:date>2012-04-05T16:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099329#M62443</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/11384"&gt;@Zeke&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/96611"&gt;@DarrenWiens2&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;I am working on a similar script but instead of just listing the selection, I want to use it as a logical parameter for executing "Calculate Geometry Attributes" on a parcel polygon.&lt;/P&gt;&lt;P&gt;So far I have built a model which works OK, except I get a field character count warning&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":face_with_rolling_eyes:"&gt;🙄&lt;/span&gt; When I export the model as a python script (see python window for the model script), I get an error saying this:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;&amp;nbsp; File "&amp;lt;string&amp;gt;", line 6&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;def # NOT IMPLEMENTED# Function Body not implemented&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;^&lt;/FONT&gt;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;SyntaxError: invalid syntax&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# -*- coding: utf-8 -*-
"""
Generated by ArcGIS ModelBuilder on : 2021-09-17 08:27:10
"""
import arcpy
def #  NOT  IMPLEMENTED# Function Body not implemented

def GeometryCalc():  # GeometryCalc

    # To allow overwriting outputs change overwriteOutput option to True.
    arcpy.env.overwriteOutput = False

    arcpy.ImportToolbox(r"c:\program files\arcgis\pro\Resources\ArcToolbox\toolboxes\Data Management Tools.tbx")
    # Model Environment settings
    with arcpy.EnvManager(scratchWorkspace=r"C:\Users\abishop\AppData\Local\Temp\ArcGISProTemp10544\1ba0f558-c873-4c6c-be6d-dc08393016c0\Default.gdb", workspace=r"C:\Users\abishop\AppData\Local\Temp\ArcGISProTemp10544\1ba0f558-c873-4c6c-be6d-dc08393016c0\Default.gdb"):
        parcel = "I:\\users\\abishop\\DATA\\CadastreCopy.gdb\\parcel"

        # Process: Select Layer By Attribute (Select Layer By Attribute) (management)
        parcel_Layer, Count = arcpy.management.SelectLayerByAttribute(in_layer_or_view=parcel, selection_type="NEW_SELECTION", where_clause="GIS_ACRES IS NULL", invert_where_clause="")

        # Process: If Selection Exists (If Selection Exists) ()
        True_48, False_49 = #  NOT  IMPLEMENTED(in_layer_or_view=parcel_Layer, selection_condition="EXISTS", count=0, count_min=0, count_max=0)

        # Process: Calculate Geometry Attributes (Calculate Geometry Attributes) (management)
        if True_48:
            parcel_Layer_2_ = arcpy.management.CalculateGeometryAttributes(in_features=parcel_Layer, geometry_property=[["GIS_ACRES", "AREA"]], length_unit="", area_unit="ACRES", coordinate_system="PROJCS[\"NAD_1983_StatePlane_Florida_West_FIPS_0902_Feet\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"D_North_American_1983\",SPHEROID[\"GRS_1980\",6378137.0,298.257222101]],PRIMEM[\"Greenwich\",0.0],UNIT[\"Degree\",0.0174532925199433]],PROJECTION[\"Transverse_Mercator\"],PARAMETER[\"False_Easting\",656166.6666666665],PARAMETER[\"False_Northing\",0.0],PARAMETER[\"Central_Meridian\",-82.0],PARAMETER[\"Scale_Factor\",0.9999411764705882],PARAMETER[\"Latitude_Of_Origin\",24.33333333333333],UNIT[\"Foot_US\",0.3048006096012192]]", coordinate_format="SAME_AS_INPUT")[0]

if __name__ == '__main__':
    GeometryCalc()&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 13:11:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099329#M62443</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-09-17T13:11:19Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099427#M62455</link>
      <description>&lt;P&gt;The line ("def #...") is not valid Python syntax. For some reason, exporting to Python script has malfunctioned - it has lots of problems. If there's supposed to be a function there, you'll have to write it yourself. If not, delete that line and continue on.&lt;/P&gt;&lt;P&gt;edit: I'm pretty sure you'll also have to edit the line&amp;nbsp;"True_48, False_49 = #"&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 16:44:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099427#M62455</guid>
      <dc:creator>DarrenWiens2</dc:creator>
      <dc:date>2021-09-17T16:44:54Z</dc:date>
    </item>
    <item>
      <title>Re: Check if any features are selected</title>
      <link>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099463#M62457</link>
      <description>&lt;P&gt;The problem with changing or eliminating the True False is that the logical condition of checking the selection will be eliminated.&amp;nbsp; I think that's why there is a malfunction.&amp;nbsp; That logical operator I used in the ModelBuilder "If Selection Exists" only works in ModelBuilder.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":sad_but_relieved_face:"&gt;😥&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 Sep 2021 17:30:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/check-if-any-features-are-selected/m-p/1099463#M62457</guid>
      <dc:creator>ABishop</dc:creator>
      <dc:date>2021-09-17T17:30:56Z</dc:date>
    </item>
  </channel>
</rss>

