Hi, I'm trying to join attributes from 12 tables to a single layer. This is the script.
import arcpy
from arcpy import env
# Set overwrite option
arcpy.env.overwriteOutput = True
arcpy.env.qualifiedFieldNames = False
# Set the current workspace.
env.workspace = r'D:\INSUMOS\INEGI\21 Puebla.mdb'
# Set local variables.
inFeatures = r'D:\INSUMOS\INEGI\21 Puebla.mdb\JOIN\mNoJoin'
layerName = 'mNoJoin_layer'
joinField = 'CVEGEO'
outFeature = r'D:\INSUMOS\INEGI\21 Puebla.mdb\JOIN\m_Join'
# Create a feature layer from the vegtype featureclass.
arcpy.MakeFeatureLayer_management (inFeatures, layerName)
# Get a list of stand alone tables in the geodatabase and print out.
tableList = arcpy.ListTables("*manzanas*")
for table in tableList:
# Join the feature layer to a tables.
arcpy.AddJoin_management(layerName, joinField, tableList, joinField)
# Copy the layer to a new permanent feature class
arcpy.CopyFeatures_management(layerName, outFeature)
print "Number of tables joined to inFeature: ", len(tableList)
print "Done."
I get this from Shell:
Traceback (most recent call last):
File "D:\Eric\python script\AddMultipleJoinToFeature.py", line 24, in <module>
arcpy.AddJoin_management(layerName, joinField, tableList, joinField)
File "C:\Program Files (x86)\ArcGIS\Desktop10.3\ArcPy\arcpy\management.py", line 6110, in AddJoin
raise e
RuntimeError: Object: Error in executing tool
I suppose this a newbie stuff, but I appreciate if you guys help me.
Solved! Go to Solution.
Hi Eric. Your AddJoin isn't working because you are trying to join the whole list of tables instead of just the current table in the loop.
Instead of:
# Get a list of stand alone tables in the geodatabase and print out.
tableList = arcpy.ListTables("*manzanas*")
for table in tableList:
# Join the feature layer to a tables.
arcpy.AddJoin_management(layerName, joinField, tableList, joinField)
Try:
# Get a list of stand alone tables in the geodatabase and print out.
tableList = arcpy.ListTables("*manzanas*")
for t in tableList:
# Join the feature layer to a tables.
arcpy.AddJoin_management(layerName, joinField, t, joinField)
Hi Eric. Your AddJoin isn't working because you are trying to join the whole list of tables instead of just the current table in the loop.
Instead of:
# Get a list of stand alone tables in the geodatabase and print out.
tableList = arcpy.ListTables("*manzanas*")
for table in tableList:
# Join the feature layer to a tables.
arcpy.AddJoin_management(layerName, joinField, tableList, joinField)
Try:
# Get a list of stand alone tables in the geodatabase and print out.
tableList = arcpy.ListTables("*manzanas*")
for t in tableList:
# Join the feature layer to a tables.
arcpy.AddJoin_management(layerName, joinField, t, joinField)
Thank you for responding.
I modified the code and run ok.