I’m working through tutorials from the book “GIS Tutorial for Python Scripting,” by David W. Allen, and I have this code pretty much exactly the way the book wants it (I altered one variable name from LayerSStations to LayerStation because the double-S was giving me problems seeing it) and every time I run it it throws the error “00840: The value is not a feature layer.”
Here’s my code, up to the point it throws the error:
import arcpy
#create a map document object for the map document
thisMap = arcpy.mapping.MapDocument(r"C:UsersAndyDocumentsGIS DataBaseEsriPressGISTPythonMapsTutorial 3-3.mxd")
#Create data frame object
myDF = arcpy.mapping.ListDataFrames(thisMap)[0]
#Create list object of the map elements
myMapElements = arcpy.mapping.ListLayoutElements(thisMap)
#Get a list of all layers in the table of contents
#Use a for loop to find layers Parcels and SamplingStations
#assign them to new variables for easier reference
myLayers = arcpy.mapping.ListLayers(myDF)
for lyr in myLayers:
if lyr.name == "Parcels":
print "Parcels have been found."
layerParcels = lyr
elif lyr.name == "SamplingStations":
print "Sampling Stations have been found."
layerStation = lyr
#create feature layer to hold only Operational sampling stations
arcpy.MakeFeatureLayer_management(layerStation,"ActiveStations_lyr",'"Status='Operational'')
It’s failing on that last command, the MakeFeatureLayer_management line. Any idea what I’m doing wrong?
I’ve been over and over the variable names looking for wrong things, I have done Rubber Duck debugging, and I can’t nail down the problem.
EDIT: Added more of the original code to the snippet.