how to define the field contents to be copied

647
1
Jump to solution
05-27-2012 04:11 PM
ElaineKuo
Occasional Contributor
System ArcGIS 9.3
Problem:

I created a new field "All" and want to copy "S" (Text) to it based on the selected rows.
However, a warning showed, saying "S" is not defined.
Please kindly advise any modification to the code below.
Thank you.

##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()
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
GSKTRYG
New Contributor III
Hi,

Provide S with in single quotes in the expression argument.

gp.CalculateField_management("outputS.shp", "All", "'S'","PYTHON_9.3")

Regards,
Siva

View solution in original post

0 Kudos
1 Reply
GSKTRYG
New Contributor III
Hi,

Provide S with in single quotes in the expression argument.

gp.CalculateField_management("outputS.shp", "All", "'S'","PYTHON_9.3")

Regards,
Siva
0 Kudos