AnsweredAssumed Answered

How to identify if 0 records are selected in a layer using python

Question asked by ahna.miller@driscolls.com_atlasdriscolls on Nov 7, 2017
Latest reply on May 1, 2018 by ahna.miller@driscolls.com_atlasdriscolls

I am currently working on a script that reads the number of features selected in a layer and returns a message or does a function based on how many records are selected. 

 

If 0 are selected:  it tells the user to "make a selection"

If >10, it tells users "too many features selected, must be less than 10"

If they select between 1-10 features, it runs the rest of the function.

 

I have the following logic:

features = int(arcpy.GetCount_management (featureLayer).getOutput(0))

 

if features<1:

 arcpy.addmessage(msg1)

 

elif features>10:

arcpy.addmessage(msg2)

 

else:

function proceeds....

 

The issue with this logic is that if no features are selected (if features<1:) it reads it as the count of the entire feature class and so returns msg2. 

 

I tried instead to use the logic of 

desc = arcpy.Describe (Featureclass)

if desc.FIDset ==' ':

arcpy.addmessage (msg1)

 

This second logic works in ArcGIS desktop, but will not work in AGOL if I publish as a Geoprocessing service.

 

Can anyone think of any workarounds that will recognize if 0 records are selected?

Outcomes