Join tables to feature classes in batch

06-13-2017 06:51 AM
New Contributor


I need some help with batch processing using python. I am trying to join fields to multiple point features classes from multiple dbf tables (650 feature classes and tables). Names of the dbf tables match names from each feature class. I have got the script so far; I am not sure where I went wrong as the script runs but feature classes are not updated with the join. I am using instead of Add Join because I want to update the feature classes directly without having to create feature layer and save. If this where I am wrong, please let me know.

Any help is highly appreciated. My script so far is below:

import arcpy, os 
from arcpy import env 
 # Add variables 
GDB1 = r"C:\test\GDB1.gdb" 
GDB2 = r"C:\test\GDB2.gdb" 
joinField = "Work_ID" 
env.workspace = GDB1  
 #Join tables 
for fc in arcpy.ListFeatureClasses():         
    env.workspace = GDB2 
    for table in arcpy.ListTables(): 
                if table() == fc(): 
                            arcpy.JoinField_management(GDB1 + os.sep + fc, joinField, GDB2 + os.sep + table, joinField, "")

                           arcpy.AddMessage("Could not join ") 
env.workspace = GDB1 

Tags (2)
0 Kudos
1 Reply
MVP Regular Contributor
  1. Not sure what's happening with if table() == fc(): Are these supposed to be custom functions? if so, could you post the code for those.
  2. It looks like you don't have any field names specified in the fields parameter, which is "the fields from the join table to be included in the join." I think you need to tell it what fields you want appended to your input feature class, otherwise it doesn't really do what you want.
  3. You're already using the os module for the path separator, you should go all the way and use os.path.join() to build your paths. /blogs/dan_patterson/2016/08/14/filenames-and-file-paths-in-python 
0 Kudos