##Script Name: calculate sum ##Description: calculate sum ##Created By: Elaine Kuo ##Date: 26/05/2012 #Import standard library modules import arcgisscripting import os #Create the Geoprocessor object gp = arcgisscripting.create(9.3) #Set the workspace. gp.Workspace= "H:/temp/test" #Set the workspace. List all of the feature classes in the dataset outWorkspace= "H:/temp" #Get a list of the featureclasses in the input folder fcs = gp.ListFeatureClasses() # Create a value table that will hold all of the input features to Merge. vt = gp.createobject("ValueTable") # 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 # Add a field to this shapefile, of type LONG gp.AddField (fc, "All", "Text", 6,6) # Populate the input value table with feature classes. vt.AddRow(fc) # Get a list of the fields in the featureclass fields = gp.ListFields(fc, "C*", "String") # Loop through every item in the list that was just generated for field in fields: gp.toolbox = "Data Management" gp.addMessage(type(field)) # Select records to be copied (C*, i.e. C7658) # Make temporary featureclasses query = "\"%s\" = 'S'" % field.Name gp.Select_analysis(fc,("outputS.shp"),query) # copy values in existing fields to the new field gp.CalculateField_management("outputS.shp", "All", "S","PYTHON_9.3") #Validate the new feature class name for the output workspace. OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace) gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Solved! Go to Solution.