MakeFeatureLayer and SelectByLocation_management()

I need to always remember this when I see the error that says “The value cannot be a feature class”. The difference between a feature layer and a feature class seems sort of nebulous to me. As long as I remember to convert a feature class to a feature layer first before doing the selection, it will work fine. For example ...


gp.MakeFeatureLayer_management("some_fc", "some_fc_Make")
gp.SelectLayerByAttribute_management("some_fc_Make", "NEW_SELECTION", "GRIDCODE = 2")

Oh and this is necessary for Select By Attribute AND Select By Location.

This is also important when using CopyFeatures. The help says this about CopyFeatures.

“Copies features from the input feature class or layer to a new feature class. If the input is a layer which has a selection, only the selected features will be copied. If the input is a geodatabase feature class or shapefile, all features will be copied. ”