#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() # 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 # Get a list of the fields in the featureclass fields = gp.listFields(fc, "C*", "String") #Select R #----------------------------------------------------------------- # 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 (C*, i.e. C7658) # Make temporary featureclasses gp.toolbox = "Data Management" query = "\"%s\" = 'R'" % field.Name gp.select_analysis(fc,("outputR.shp"),query) gp.Dissolve_management(fc,("outputR.shp"), field.Name) #get file name fcName, fcExt = os.path.splitext(fc) # replace the strings you want to fcName = fcName.replace("_Dissolve","") fcName = fcName + fcExt gp.rename_management("outputR.shp", fcName) gp.delete("outputR.shp") gp.AddMessage(gp.GetMessages()) print gp.GetMessages()
Solved! Go to Solution.
#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() # 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 #Validate the new feature class name for the output workspace. OutFeatureClass = outWorkspace + os.sep + gp.ValidateTableName(fc,outWorkspace) #get file name fcName, fcExt = os.path.splitext(fc) # Get a list of the fields in the featureclass fields = gp.listFields(fc, "C*", "String") # replace the strings you want to fcName = fcName.replace("_Dissolve","") fcName = fcName + fcExt fcName = outWorkspace + os.sep + fcName gp.Dissolve_management(fc,OutFeatureClass, field.Name)
# Loop through every item in the list that was just generated for fc in fcs: #get file name fcName, fcExt = os.path.splitext(fc) # Get a list of the fields in the featureclass fields = gp.listFields(fc, "C*", "String") # Is 'fields' supposed to contain a single field? If so, then you need this line: field = fields[0] # replace the strings you want to fcName = os.path.join(outWorkspace, fcName + "_Dissolve") + fcExt gp.Dissolve_management(fc, fcName, field.Name)