Select to view content in your preferred language

"Dataset xxx does not exist or is not supported" using Table to Domain in Python

723
2
07-22-2012 11:06 PM
StephenLead
Honored Contributor
I have a directory of hundreds of *.csv files, containing code/description pairs for geodatabase domains. I'm trying to automate the creation of these domains using Python.

1) If I manually run the Table to Domain tool using a *.csv file in ArcToolbox, the domain is correctly created
2) If I create a Model using the Table to Domain tool, hard-coding in the input file (and all other parameters) then export this to a Python script, the domain is correctly created when I run the Python script
3) If I try to iterate through all *.csv files in the directory, running the Table to Domain tool for each file, I get the ""Dataset xxx does not exist or is not supported" error message:

Failed to execute. Parameters are not valid.ERROR 000732: Input Table: Dataset C:\temp\01-01.csv does not exist or is not supported
ERROR 000308: Invalid field type
Failed to execute (TableToDomain).


I suspect the problem is due to the path not being correct for the *.csv file, but I can't work out how to get it working. os.path.exists shows that the file does exist, so it may be an internal ArcGIS thing.

Note that the *.csv file does work correctly via ArcToolbox and the hard-coded Python script, so it's unlikely that the field type really is invalid.

Any help gratefully received.

Thanks,
Steve
Tags (2)
0 Kudos
2 Replies
AndrewChapkowski
Esri Regular Contributor
It looks like your issue is that the csv file is open, and the arcpy function cannot work on the open/locked file.

Try this:
# Import system modules
import arcpy
from arcpy import env
import os
 
try:
    directory = "C:/temp/cert"
    os.chdir(directory)
    env.workspace = directory

    gdb = "template.gdb"
    extension = ".csv"

    # get a listing of all CSV files    
    for myfile in os.listdir("."):
        if myfile.endswith(extension):

            #read in the domain values from the file
            f = open(myfile, 'r')
            header = f.readline().split(",")
            code = header[0]
            desc = header[1].rstrip().lstrip()
            f.close()
            del f
            #Set local parameters
            domTable = os.path.abspath(myfile)
            codeField = code
            descField = desc
            dWorkspace = gdb
            domName = myfile.split(extension)[0] #the domain takes on the name of the file, minus the ".csv" section
            domDesc = desc.replace("_"," ")

            print domTable, codeField, descField, dWorkspace, domName, domDesc
            print os.path.exists(domTable)

            arcpy.TableToDomain_management(domTable, codeField, descField, dWorkspace, domName, domDesc,"REPLACE")

            #f.close()
 
except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message
0 Kudos
StephenLead
Honored Contributor
It looks like your issue is that the csv file is open, and the arcpy function cannot work on the open/locked file.


Bingo. Thanks for that.

Believe it or not, this answer actually popped into my head while I was brushing my teeth last night.
0 Kudos