Join tables to feature classes in batch

1055
1
06-13-2017 06:51 AM
PadminiBharadwaj
New Contributor

Hello,

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 arcpy.joinField.management 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(): 
        try: 
                if table() == fc(): 
                    try:                              
                       
                            arcpy.JoinField_management(GDB1 + os.sep + fc, joinField, GDB2 + os.sep + table, joinField, "")

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

Tags (2)
0 Kudos
1 Reply
BlakeTerhune
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