RuntimeError: Object: Error in executing tool (in AddJoin)

10870
2
Jump to solution
03-03-2016 07:30 AM
G__EricCastillo_Morales
New Contributor III

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.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RuthBowers
New Contributor III

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)

View solution in original post

0 Kudos
2 Replies
RuthBowers
New Contributor III

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)

0 Kudos
G__EricCastillo_Morales
New Contributor III

Thank you for responding.

I modified the code and run ok.

0 Kudos