Select to view content in your preferred language

Make Query Table works in Python Window but not as Tool???

7092
11
06-25-2014 09:00 AM
LonnieBilyk
New Contributor
Hi,

I'm a newbie at coding, so I hope my question is clear.

The below code works perfectly when I run it in the Python Window of 10.1.

But when I make a tool and attach the script, it runs and indicates that the script completed successfully but yet the table is not added to the TOC. Why will it not automatically appear?

Any ideas? I've tried so many things to make the table appear, I can't even remember anymore.

Lonnie




import arcpy, datetime, arcgisscripting, os
from arcpy import env

# Local variables.
tableList = "Database Connections/Database.odc/FWS_WMIS.FWI_INVENTORY_PROJECT;Database Connections/Database.odc/FWS_WMIS.FWI_INVENTORY_SURVEY"
   
fieldList = "FWS_WMIS.FWI_INVENTORY_PROJECT.INV_PROJ_ID 'INVENTORY_PROJECT_ID';FWS_WMIS.FWI_INVENTORY_SURVEY.INV_SURVEY_ID 'INV_SURV_ID';FWS_WMIS.FWI_SURVEY_CREW_FNC(FWS_WMIS.FWI_INVENTORY_SURVEY.INV_SURVEY_ID) 'SURVEY_CREW'"
whereClause = "FWS_WMIS.FWI_INVENTORY_PROJECT.INV_PROJ_ID=FWS_WMIS.FWI_INVENTORY_SURVEY.INV_PROJ_ID AND FWS_WMIS.FWI_INVENTORY_PROJECT.INV_PROJ_ID=17909"
keyField = "FWS_WMIS.FWI_INVENTORY_PROJECT.INV_PROJ_ID"

#Get the current date and time.
now = datetime.datetime.now()

#Use the current time as the name for the layer to produce a unique name for every layer.
lyrName = now
   
# Make Query Table.
arcpy.MakeQueryTable_management(tableList, lyrName,"USE_KEY_FIELDS", keyField, fieldList, whereClause)
Tags (2)
0 Kudos
11 Replies
curtvprice
MVP Esteemed Contributor

CopyFeatures will not work on the Make Query Table results because it's not a feature class -- it's a table view object. Have you tried CopyRows?

0 Kudos
TomBrabant
New Contributor

Curtis, CopyRows worked! Thanks! The output appeared as a table to  catalog window inside the geodatabase, and from there could optionally be added to the TOC if needed.

I was also able to instantiate a SearchCursor on the "invisible" tableview that I copied rows from. I could have sworn I tried that yesterday, but maybe I never did.

0 Kudos