ArcGIS 10.2, Windows 10

this is the line that fails:

arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", gridLayer, "", "NEW_SELECTION")

The WRS_layer is in a file gdb, the gridLayer is in an SDE gdb. Both are polygon feature classes. SDE layers are being edited by a user-initiated edit session, but in this addin button there is no arcpy.da.Editor. The SelectByLocation will work fine for a while, and then starts giving an error message:

Traceback (most recent call last):
File "C:\Users\...\ESRI\Desktop10.2\AssemblyCache\{1E...D8E}\NORDIS_Landsat.py", line 432, in onClick
   arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")
File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6812, in SelectLayerByLocation
    raise e
ExecuteError: ERROR 999999: Error executing function.
General function failure
General function failure [WRS2_Nordis]
Failed to execute (SelectLayerByLocation).

Here is the referenced line in management.py

6806      from arcpy.geoprocessing._base import gp, gp_fixargs
6807    from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject
6808    try:
6809        retval = convertArcObjectToPythonObject(gp.SelectLayerByLocation_management(*gp_fixargs((in_layer, overlap_type, select_features, search_distance, selection_type), True)))
6810        return retval
6811    except Exception, e:
6812        raise e

Arcmap doesn't crash, but only a restart of ArcMap solves the problem. I don't think this is a code problem, but I hope that someone else has experienced something similar and can suggest a cause and/or solution.

EDIT: as requested, here is the top part of the button's code immed after def onClick(self)

mxd = arcpy.mapping.MapDocument("CURRENT")
Error = False
WRS_layer          = "WRS2_Nordis"
WRS_fields         = ["PR"]
username           = getpass.getuser().lower()
rastersPresent     = []
rastersMissing     = []

layersPresent = []
for lyr in arcpy.mapping.ListLayers(mxd):
for lyrReqd in (WRS_layer, progressLayerName):
    if not lyrReqd in layersPresent:
        Error = True
        print "ERROR: cannot find layer  ", lyrReqd, "  in the TOC."

d = arcpy.Describe(progressLayerName)
if len(d.FIDSet) == 0:
    ProgressGrid_Select = 0
    ProgressGrid_Select = len(d.FIDSet.split(";"))
if ProgressGrid_Select <> 1:
    print " You have", str(ProgressGrid_Select), " ProgressGrid cells selected  -- should be exactly 1."
    Error = True

# make a WRS list of lists, with PathRow

if not Error:
    # SelectLayerByLocation HONOURS THE SELECTION SET IN in_layer
    print 'DEBUG: attempting SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")'
    arcpy.SelectLayerByLocation_management(WRS_layer, "INTERSECT", progressLayerName, "", "NEW_SELECTION")
    #  make list of WRS scenes, with PR (data type Long)
    WRS_scenes = []
    # SearchCursor (in_table, field_names, {where_clause}, {spatial_reference}, {explode_to_points}, {sql_clause})
    with arcpy.da.SearchCursor(WRS_layer,WRS_fields) as cursor:
        for row in cursor:

    if len(WRS_scenes) == 0:
        print "No WRS_scenes intersect with selected Progress Grid cell."
        Error = True
        print "Found " + str(len(WRS_scenes)) + " WRS scenes for selected progress cell:"
        prs = ''
        for pr in WRS_scenes:
            prs += ("  " + str(pr))
        print prs

closed as off-topic by PolyGeo Sep 6 '16 at 7:07

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This problem cannot or can no longer be reproduced. Changes to the system or to the asker's circumstances may have rendered the question obsolete, or the question does not include a procedure to enable potential answerers to reproduce the same symptoms. Such questions are off-topic as they are unlikely to help future readers, but editing them to include more details can lead to re-opening." – PolyGeo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Those cursed ERROR 999999 messages. This error could mean anything that the developer didn't anticipate originally. Try calling repair geometry on your gridLayer and WRS_layer feature class just in case a bowtie or incorrect ring orientation has the selection engine confused. If there's changes in these datasets expected call as part of the script or if they're static run repair in catalog just once on both. – Michael Stimson May 3 '16 at 22:20
  • Is this in any loop in your addin or does the user have to press a button or click on the map to run a tool each time. Are you cleaning up everything before completing each button press or tool operation? Do you have an extension going? With at least 432 lines of code in your addin you more than likely have created code than is a bit more complex sequence than a simple SelectLayerByAttribute operation. The greater the complexity, the more likely you are not cleaning up after yourself. Also, is the user able to select more features than SDE memory is configured to return? – Richard Fairhurst May 3 '16 at 23:08
  • Can you please include a snippet around line 432 of your code rather than from management.py? – Midavalo May 3 '16 at 23:54
  • I wonder if it could be a projection/coordinate system issue. Do they have the same spatial reference? Also, turning off background processing sometimes works better for more complex geoprocessing resources.arcgis.com/en/help/main/10.2/index.html#//… – dslamb May 4 '16 at 12:53
  • @Micheal OK, I've manually repaired geometry on the WRS_layer, it's not editable so I shouldn't need to call it in the script. The gridLayer is in the SDE, so can't repair geometry there, it's supposed to be handled by the SDE. – AMurray May 4 '16 at 16:41