Is it possible to use an existent layer to do a selection by attributes without having to use
MakeFeatureLayer_management first? Because I already have a layer with the same name as the feature class "Rede_Cbr_MM_2008_proj".
Only this code works for me:
import arcpy from arcpy import env # Set workspace env.workspace = "S:/workspace/MSc_git/ArcGis/estagio_db.gdb" workspace = "S:/workspace/MSc_git/ArcGis/Layers" in_feature= "Rede_Cbr_MM_2008_proj" tmp_layer="tmp_layer" # # Set overwrite option # arcpy.env.overwriteOutput = True #MakeFeatureLayer variables where_clause='TSYSSET NOT LIKE \'%Metro%\'' try: #Make a layer from the feature class arcpy.MakeFeatureLayer_management(in_feature,tmp_layer) arcpy.SelectLayerByAttribute_management(tmp_layer,"NEW_SELECTION",where_clause) # Write the selected features to a new featureclass arcpy.CopyFeatures_management(tmp_layer, "Rede_Cbr_MM_2008_WithoutMetro") except: print arcpy.GetMessages()
But if I try to use my layer using only
SelectLayerByAttribute_management I get this error:
Executing: SelectLayerByAttribute S:/workspace/MSc_git/ArcGis/Layers/Rede_Cbr_MM_2008_proj.lyr NEW_SELECTION "TSYSSET NOT LIKE '%Metro%'" Start Time: Sat Jul 20 21:49:55 2013 Failed to execute. Parameters are not valid. ERROR 000825: The value is not a layer or table view ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute).
SelectLayerByAttribute supposed to take a layer as 1st parameter? I don't know I do I have to do this kind of "layer on the fly" (
tmp_layer) and then select.