AnsweredAssumed Answered

batch join field using python

Question asked by helenak on Jun 29, 2013
Latest reply on Jun 30, 2013 by rfairhur24
Hello

System vista and ArcGIS 9.3

I want to join the field of a grid shape file (file A) to 50 shape files (file B) in one folder.
File A has a field called ???GID.???
Each of the file B also has one field ???GID.???
Therefore, GID is the base field to join file A and B.

I wrote a code for the purpose but did not work.
The problems could be:

1. gp.MakeFeatureLayer_management (outFeatureClass, "outFeatureClass_lyr")
    ExecuteError: Failed to execute. Parameters are not valid.


2. ERROR 000732:
    Input Features: Dataset H:/temp_D\geoc0283_shp does not exist or is not supported
    Failed to execute (MakeFeatureLayer).

Thank you.

################################################## ######################## ##AddJoin feature layers to a feature layer ##Elaine Kuo ##30 June 2013 ################################################## #######################  #Import standard library modules import arcgisscripting import os  #Create the Geoprocessor object gp = arcgisscripting.create(9.3)  # Load required toolboxes... ## gp.AddToolbox("C:\Program Files\ArcGIS\ArcToolbox\Toolboxes\Data Management Tools.tbx") ## no need for system toolboxes  #Set the input workspace workingfolder = "H:/temp_D/test"  source = "H:/temp_D/testt/A_grid.shp"  outputfolder = "H:/temp_D"  #Set workspace gp.Workspace = workingfolder  #Set the output workspace outWorkspace= outputfolder  #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:          #Validate the new feature class name for the output workspace.     outFeatureClass = outWorkspace + os.sep +gp.ValidateTableName(fc,outWorkspace)     gp.Toolbox = "Data Management"     gp.MakeFeatureLayer_management (outFeatureClass, "outFeatureClass_lyr")          # make a layer for source     gp.MakeFeatureLayer_management (source, "source_lyr")      # Make temporary featureclasses     gp.MakeFeatureLayer(fc,"lyr")      # have Layers for AddJoin     gp.AddJoin_management("source_lyr", "GID", "lyr", "GID", "KEEP_ALL")      gp.CopyFeatures_management ("source_lyr", "outFeatureClass_lyr")     gp.FeatureClassToShapefile_conversion("outFeatureClass_lyr", outputfolder)      # clear memory of layers     gp.Delete("source_lyr")     gp.Delete("lyr")     gp.Delete("outFeatureClass_lyr")      gp.AddMessage(gp.GetMessages()) print gp.GetMessages()

Outcomes