stain3565

SelectLayerByAttribute issue

Discussion created by stain3565 on Jun 16, 2014
Latest reply on Jun 16, 2014 by doug.sands
I have had issues whereby a SelectLayerByAttribute CLEAR_SELECTION and NEW_SELECTION is producing "The value cannot be a feature class" messages.

I googled this and found that I should make my class a layer either by using MakeFeatureLayer or MakeTableView for the layer to be selected.

I tried both these but still get the same message.

Any help would be appreciated. My code is below:

import arcpy, sys, math, os, datetime, traceback
import arcpy.mapping as map
from arcpy import da, env

XYPointsLayer = layerMemory + os.sep + "XYPointsLayer"
XYPointsLayerIntersect = layerMemory + os.sep + "XYPointsLayerIntersect"
#arcpy.MakeXYEventLayer_management(WorkLayerName, viewName  + ".GRID_X", viewName  + ".GRID_Y", XYPointsLayer)
arcpy.MakeXYEventLayer_management(fullviewName, "GRID_X", "GRID_Y", XYPointsLayer)
#### Note looks like using the view directly may work instead of the MakeQueryTable option
arcpy.MakeTableView_management(XYPointsLayer, XYPointsLayerIntersect)
#arcpy.MakeFeatureLayer_management(XYPointsLayer, XYPointsLayerIntersect)

viewName = "DWOP.DBO.VWO_MDPAG_DPA_WORK"
fullviewName = arcpy.env.workspace + os.sep + viewName


arcpy.SelectLayerByAttribute_management(XYPointsLayerIntersect,"CLEAR_SELECTION")
arcpy.SelectLayerByAttribute_management(XYPointsLayerIntersect,"NEW_SELECTION","TIMESTAMP0 = '20140613 08:59:58.063' and FK_ROADLINK_TOID = 'PEGASUS005108964' and AP_ID_ARRAY1 = '141863003'")


The SelectLayerByAttribute is within an "for" statement in the original code so i am wondering if this may be an issue? Also, the "NEW_SELECTION" criteria are in a variable in the original code but I have traced this and cut and pasted these in just to show the criteria used. However, it fails on the CLEAR_SELECTION first.

The issue seems to be the basic interpretation of what XYPointsLayerIntersect actually is.

Any ideas?

Outcomes