You can actually do this very easily. If you have a layer object and you want to test if there are any selected features, you can use this function:
def verifySelection(lyr):
return bool(arcpy.Describe(lyr).FIDSet)
If you are creating a new layer using make feature layer, you can simply check the count:
def verifyCount(lyr):
return bool(int(arcpy.management.GetCount(lyr).getOutput(0)))
Take this example, where I have a zoning layer in ArcMap. I can test if anything was selected like this:
>>> where_good = "Zone_Code = 'C-1'"
>>> arcpy.management.SelectLayerByAttribute("Zoning", "NEW_SELECTION", where_good)
<Result 'Zoning'>
>>> def verifySelection(lyr):
... return bool(arcpy.Describe(lyr).FIDSet)
...
>>> verifySelection('Zoning')
True
>>> where_bad = "Zone_Code = 'not a real value'"
>>> arcpy.management.SelectLayerByAttribute("Zoning", "NEW_SELECTION", where_bad)
<Result 'Zoning'>
>>> verifySelection('Zoning')
False
>>>
The FIDSet
returns a semicolon delimited list of selected OID's. This is from after I ran the "where_good"
query:
>>> print arcpy.Describe('Zoning').FIDSet
1; 2; 3; 4; 5
And you can do the same thing by making new feature layers from the zoning layer and calling the verifyCount()
to see that there were actually output features.