PROBLEM

SearchCursor returns no results after Select By Location is run

Last Published: April 26, 2024

Description

If a search cursor is run on a feature class, it returns all features. However, if a selection tool (such as Select By Location) is run prior to the search cursor, and nothing is selected, the search cursor returns no results.

Cause

This is expected behavior. ArcMap recognizes if a selection has been run on a feature class and only returns selected features. If no features were selected, no features are returned after the search has been run.

Solution or Workaround

To workaround this issue, use a Python script and add an if statement that clears any selections.
if count == 0:
  arcpy.SelectLayerByAttribute_management("Box","CLEAR_SELECTION")

Article ID: 000014447

Software:
  • ArcMap

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options