In a sentence, how do you test in Arcpy whether a feature class has any selected records or not? More info below to explain:

I am doing a batch process in which a sampling layer (10km grids) is used to select polygon records (of which there are about 100,000 in total). My script returns the list of polygon IDs that intersect each 10km grid square. I then do some further processing/summarizing using that list of polygon IDs.

In instances where there are polygons within the sample square, ArcGIS performs a selection on the polygons, and it's relatively easy to iterate through those records using a searchcursor. Note I'm using v10.0.

But in instances where there are no selected records (ie there are no polygons intersecting my 10km sample square), the searchcursor would return ALL records in the database. So what's the most robust way to test programatically whether a feature class has a selection or not?

I know you can use arcpy.GetCount_management to return a number that tells you how many records are selected, and if that number = the number of records in the entire layer then you can infer that either none, or all are selected.

But that's not the same as determining if there is a selection or not. What's the best way to do that in Arcpy?

  • 2
    I don't understand how you proceed. If your selection doesn't return any record, then it will be empty, it won't include all records. Then using GetCount is not ambiguous. Can you show your code?
    – GISGe
    Commented Feb 11, 2014 at 10:46
  • But that's the point, there is no selection, therefore getcount returns all records rather than zero. There's no such thing as a selection that doesn't return a record; rather, it's a query (whether by attribute or location) that returns no selection. Therefore getcount returns all records. In any event I have a solution which I'll post in a sec...
    – TreeMan
    Commented Feb 11, 2014 at 11:03

1 Answer 1


After some more digging, this post answers my question: http://blog.technicallyliving.com/2013/08/arcpy-testing-for-selected-features/


u'3; 4; 5; 6'

The author says "FIDSet will return a semicolon delineated string of selected FIDs. When none are selected, it is blank". Problem solved, I think. Any other solutions would be welcome

Therefore, to test in Arcpy whether a feature class has any selected records or not you can simply use:

if arcpy.Describe("layer_name").fidSet:
    #manipulate the selection
  • 1
    This is a pretty classic question and IMO the solution you found is best.
    – KHibma
    Commented Feb 11, 2014 at 14:51
  • 1
    As noted in the link provided by @Jason Scheirer, using sel_count = len(desc.fidSet.split(";")) will effectively give you the equivalent of a GetSelectionCount utility, which would make it easier to validate using if sel_count > 0: do something. Commented Feb 11, 2014 at 16:25
  • @RyanDalton sel_count can't be 0 as split on an empty string returns an array of size 1
    – Miro
    Commented Feb 27, 2019 at 0:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.