##Script Name: Delete rows ##Description: delete selected rows ##Created By: Elaine Kuo ##Date: 04/05/2012 #Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) #Set the input workspace #GP.workspace = sys.argv[1] #Set the workspace. gp.Workspace= "G:/temp" #Set the output workspace #outWorkspace = sys.argv[2] #Set the workspace. List all of the feature classes in the dataset outWorkspace= "G:/temp/test" #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Loop through every item in the list that was just generated for fc in fcs: # Break out the name, no path or extension, using the describe object. desc = gp.describe(fc) featureName = desc.name # Make featureclasses as layers gp.OverWriteOutput = 1 gp.toolbox = "Data Management" gp.MakeFeatureLayer("geor0313_p.shp","geor0313_p_lyr") #Get a list of the fields in the featureclass fields = gp.ListFields("geor0313_p_lyr", "C*", "String") # Loop through every item in the list that was just generated for field in fields: gp.toolbox = "Data Management" # Select records to be deleted (C*, i.e. C7658) query = "\"C*\" = 'R'" gp.SelectLayerByAttribute("geor0313_p_lyr", "ADD_TO_SELECTION", query) # Delete selected records gp.deleterows("geor0313_p_lyr") #Validate the new feature class name for the output workspace. outFeatureClass = outWorkspace + os.sep +GP.ValidateTableName("geor0313_p_lyr",outWorkspace)
Solved! Go to Solution.
print type(field)
query = "\"%s\" = 'R'" % field
##Script Name: Delete rows
##Description: delete selected rows
##Created By: Elaine Kuo
##Date: 04/05/2012
#Import standard library modules
import arcgisscripting
import os
#Create the Geoprocessor object
gp = arcgisscripting.create(9.3)
#Set the input workspace
#GP.workspace = sys.argv[1]
#Set the workspace.
gp.Workspace= "G:/temp"
#Set the output workspace
#outWorkspace = sys.argv[2]
#Set the workspace. List all of the feature classes in the dataset
outWorkspace= "G:/temp/test"
#Get a list of the featureclasses in the input folder
fcs = gp.ListFeatureClasses()
# Loop through every item in the list that was just generated
for fc in fcs:
# Break out the name, no path or extension, using the describe object.
desc = gp.describe(fc)
featureName = desc.name
# Make featureclasses as layers
gp.OverWriteOutput = 1
gp.toolbox = "Data Management"
gp.MakeFeatureLayer("geor0313_p.shp","geor0313_p_lyr")
#Get a list of the fields in the featureclass
fields = gp.ListFields("geor0313_p_lyr", "C*", "String")
# Loop through every item in the list that was just generated
for field in fields:
gp.toolbox = "Data Management"
# Select records to be deleted (C*, i.e. C7658)
query = "\"%s\" = 'R'" % field
gp.SelectLayerByAttribute("geor0313_p_lyr", "ADD_TO_SELECTION", query)
# Delete selected records
gp.deleterows("geor0313_p_lyr")
#Validate the new feature class name for the output workspace.
outFeatureClass = outWorkspace + os.sep +GP.ValidateTableName("geor0313_p_lyr",outWorkspace)
query = "\"%s\" = 'R'" % field.Name
print type(field)