AnsweredAssumed Answered

Check if any features are selected

Question asked by recurvata on Apr 4, 2012
Latest reply on Apr 5, 2012 by recurvata
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 if 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.

Is there a way to just check if any are selected - a HasSelected type of property? Thanks.

# check how many parcels are selected     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      # if no parcels are selected, inform user and exit script     if count < 1:         arcpy.AddError("No features selected! \n Please select at least one parcel feature. \n")         arcpy.AddError("Quitting the Create Case tool \n")         sys.exit("Goodbye! Try again!")

Outcomes