louearly

Make feature layer > Select by attributes loop

Discussion created by louearly on Apr 30, 2012
Latest reply on Jul 5, 2012 by SolomonP
This is my first adventure into Python scripting so excuse my ignorance. I am trying to loop through FC's in a GDB and select by an attribute then copy those feature classes into the GDB. Below is my script so far. Where my question lies is, in the 'SelectLayerByAttribute' process how do I specify the feature layer that was created in the previous step as the FC to do the selecting from? See where my question marks are below, that is where im unsure

import arcpy
from arcpy import env

env.workspace = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"

# Local Variables
GDB = r"\\Wmsmonfs01\gisprod\SDE Data Files\PERMITTING_ABA.gdb"

# Get a list of all feature classes
fcList = arcpy.ListFeatureClasses()

# Loop through each feature class in the GDB
for fc in fcList:

# Put in error trapping in case an error occurs when running tool
try:

# Make a layer from the feature classes
arcpy.MakeFeatureLayer_management(fc, fc + '_LYR')

# Select features by attribute
arcpy.SelectLayerByAttribute_management("?????????", "NEW_SELECTION", "\"Source\" = 'GAI'")

# Copy selected features to GDB
arcpy.CopyFeatures_management("???????", GDB)

Outcomes