I'm in the process of transferring all the arcpy scripts I've written to geoprocessing tools so that my team can run them without my hand-holding and it's *mostly* working out ok but I'm running into snags here and there and my current one has to do with the geoprocessing tool complaining about an invalid SQL expression. It throws "arcgisscripting.ExecuteError: ERROR 000358: Invalid expression" when it gets to the SelectLayerByAttributes portion, an issue that does not happen when run from the python console. my entire script runs just fine via console, but breaks when run as a GP tool. The temp layer, btw, was created by an in_memory feature class if that's relevant.
with arcpy.da.SearchCursor(temp_worklocation_layer, "OID@") as locations:
for point in locations:
cur_point_sql = f"OBJECTID={point[0]}"
arcpy.management.SelectLayerByAttribute(temp_worklocation_layer, "CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(temp_worklocation_layer, 'NEW_SELECTION', cur_point_sql)
Do GP tools handle SQL queries in a slightly different format than whatever handles it in the python console? Why does "OBJECTID = #" work in one but not the other?
Also slightly related, but this method of grabbing multiple features and then iterating back through them with the OID one at a time and doing a SelectLayerByLocation to grab other layers' features nearby is something I do numerous times across my scripts. Is that the most efficient way? Am I doing something redundant?