I am using ArGIS Desktop Standard 10.4.1 with Python 2.7.11, and am a S elf-taught Python scripter.
I've researched this extensively but there doesn't appear to be anything newer than 2014.
I am trying to test if a feature layer has a selection or not. I'm doing this via my own python script in ArcToolbox.
Essentially what is happening is that the length of len(arcpy.Describe(lyr).fidSet.split(";")) when no features are selected is returning 1. Prior posts on this subject indicate that it should return 0. Below is some very simple code:
lyr = arcpy.GetParameterAsText(0) # parameter is a feature layer arcpy.AddMessage(len(arcpy.Describe(lyr).fidSet.split(";"))) arcpy.AddMessage(arcpy.Describe(lyr).fidSet.split(";")) if len(arcpy.Describe(lyr).fidSet.split(";")) > 0: arcpy.AddMessage("Has Selection") else: arcpy.AddMessage("No Selection")
If zero feature are selected this returns
1 [u''] Has Selection
If one feature is selected it returns
1 [u'5'] Has Selection
If more than one feature is selected it returns
9 [u'1', u' 2', u' 3', u' 4', u' 5', u' 6', u' 7', u' 8', u' 9'] Has Selection
I've tried testing the returned string with is None and also putting not in front of the length statement, but those still return Has Selection when no features are selected.