Execute "Make Query Table"  tool using python

636
2
02-04-2014 10:37 AM
AnanyaBaruah
New Contributor
I am trying to execute the Make Query Table tool using Python scripts following which I will incorporate other tools as well. I have set all the required parameters for the tool to run; the input feature class, input table, the field list and the expression, etc. However, I get a Runtime error that says "RuntimeError: Object: Error in executing tool".

I am attaching the script here for your reference. I will really appreciate if someone can offer me some advice as to where I am making a mistake or what am I missing and how I can get this to work. I am a beginner with Python and any suggestions will be really helpful for me to build upon.

Thank You!
Tags (2)
0 Kudos
2 Replies
XanderBakker
Esri Esteemed Contributor
Hi Ananya,

Tip 1:specify a workspace without trailing slashes:
replace:
inputPath = "F:\\GIS\\_Projects\\NPMRDS\\GDB\\NHS_npmrds_2013.gdb\\"


by:
inputPath = "F:\\GIS\\_Projects\\NPMRDS\\GDB\\NHS_npmrds_2013.gdb"



Tip 2: It is better to use os.path.join to join a location and a name:
Add this to the beginning of the script:
import os 

and change your code to:
inputTable = os.path.join(inputPath, speedTable)

(this should give the same result as you already had)

Do the same for inputFC, tmpQueryTable, QueryTableFeatureClass:
inputFC = os.path.join(inputPath, featureClass)
tmpQueryTable = os.path.join(inputPath, "QueryTable")
QueryTableFeatureClass = os.path.join(inputPath, "copyFeatures")



Tip 3: your fieldList contains objects and not the  fully qualified field names.
In order to get this right, the easiest way would be to execute the tool manually. See instructions here:
http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000006r000000

After a successful run, open the "Results" window and right click on the successfully executed tool. This will reveal the option "Copy as Python Snippet". Now you are able to paste the python code to your Python IDE and examine what the content of each parameter has been. Adapt you script to create the same type of parameters.

Tip 4: expression is not valid
The expression uses names of variables, but should use the content of the variables. Use this instead and verify if you need to use fully qualified names in the expression.
expression = "{0} = {1}".format(tmc1, tmc4)

this would yield: "NHS_tmc = tmc"

Kind regards,

Xander
0 Kudos
AnanyaBaruah
New Contributor
Thanks for your tips Xander!

I still cannot get the tool to work right with my local variables. The main issue is with the the expression and the field list. I want only some fields from the feature class and one field from the table. I was able to get the list of these fields and also the SQL expression that you suggested worked fine outside the tool. But once I compile all these variables into the tool in python, it fails.

Any suggestions on that?

Regards
Ananya
0 Kudos