ArcPy Select By Attribute – Resolving Error 000840 on .Shp Files

arcpyerror-000840select-by-attribute

I have a script that calculating vertices angles on Polyline layer and the selecting features in that layer at a specified angle. at the end of the script i'm using select by attribute
and getting error 000840 the value is not raster layer, the value is not mosaic layer

SelectLayerByAttribute_management(my_shp_name, 'NEW_SELECTION', myquery)

Best Answer

This is a common error that I have run across, and I am pretty sure it is related to attempting to run the selection against a raw featureclass/shapefile output, as opposed to the "layer" representation of the featureclass/shapefile.

For example: You cannot select features from a shapefile without using ArcMap, but once you load the shapefile into ArcMap (which makes it a "layer"), you can now select the features from the layer.

Try using the MakeFeatureLayer_management(my_shp_name, my_shp_layer) function between the previous function's output and the SelectLayerByAttribute_management(). I think you will find that this resolves your error.

Related Question