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")
# SET SOME VARIABLES
Error = False
WRS_layer = "WRS2_Nordis"
WRS_fields = ["PR"]
username = getpass.getuser().lower()
rastersPresent = []
rastersMissing = []
# 0. VERIFY THAT THE REQUIRED LAYERS ARE PRESENT IN THE MXD.
print
layersPresent = []
for lyr in arcpy.mapping.ListLayers(mxd):
layersPresent.append(lyr.name)
for lyrReqd in (WRS_layer, progressLayerName):
if not lyrReqd in layersPresent:
Error = True
print "ERROR: cannot find layer ", lyrReqd, " in the TOC."
# 1. GET THE SELECTED GRID CELL
d = arcpy.Describe(progressLayerName)
if len(d.FIDSet) == 0:
ProgressGrid_Select = 0
else:
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
# 2. GET THE INTERSECTING WRS SCENES
# 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:
WRS_scenes.append(row[0])
if len(WRS_scenes) == 0:
print "No WRS_scenes intersect with selected Progress Grid cell."
Error = True
else:
print "Found " + str(len(WRS_scenes)) + " WRS scenes for selected progress cell:"
WRS_scenes.sort()
prs = ''
for pr in WRS_scenes:
prs += (" " + str(pr))
print prs
print