Script tool Execute Error

3494
6
02-27-2016 10:30 AM
ElenaWenz
New Contributor

Hi,

I create a script tool to iterate over tables in a folder with the XY to line tool to create one shapefile for each table. I get the following error message:

File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\management.py", line 3160, in XYToLine

    raise e

ExecuteError: Failed to execute. Parameters are not valid.

ERROR 000732: Input Table: Dataset myout1.csv does not exist or is not supported

Failed to execute (XYToLine).

The file exists, and it is also suitable as input for the XY to Line tool (I can use it as input file in ArcMap, also if I quit iterating and set the path as string it works fine). If I test the iteration code in a python script it also works, each file is accessed. Any ideas what could be the problem?

This is my code:

I have not listed all tool parameters since the code is long and I do not think that is the problem.

And  I have managed to do this in modelbuilder but I need it in python for university.

I would be grateful for any help!

0 Kudos
6 Replies
DanPatterson_Retired
MVP Emeritus

from XY To Line—Help | ArcGIS for Desktop

if you use text files and .csv (comma-separated value) files as input, make sure that they follow the file structure specified in  About tabular data sources.

Have you tested it manually and examined the Results window output to get the exact syntax?

Using the Results window—Help | ArcGIS for Desktop

ElenaWenz
New Contributor

The tables work fine with the xy to line tool (standard ArcGIS tool, script, ModelBuilder), just with this iterating code I get the error message. The code to iterate over the files also works fine when I use it in other circumstances though. The script accesses the input tables but does not seem to accept them as correct input parameters even though they are.

I am not sure what you mean by "get the exact syntax", in the Results window I get the same information as in the pop-up window after the script has failed (or succeeded).

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you have a run that succeeds and a run that fails.. the comparison from the outputs in the results window, will identify the differences.  You may have to compare your environments settings in the results output since sometimes it is a simple, but unreported and assumed difference in the operating environment.  Again, I am not talking about the printed results from a run, but the actual results window as I reported in my last link.

PS just a Q... have you ever had problems using Dropbox as an origin/destination for files before?

0 Kudos
ModyBuchbinder
Esri Regular Contributor

The error message is on myout1.csv.

When you just run the GP on this file manually - does it works?

If you remove this file from the directory does it fail on the second file?

Sometime there are hidden chars in the file name.

Try to do something like this:

print ("[%s]" % infile)

and see if the print looks fine.

Have fun

JamesCrandall
MVP Frequent Contributor

Just a wild guess and I haven't tested or attempted to run this idea but perhaps you should try to copy each input table to in_memory workspace first and use that as the input, then delete it from the workspace after each iteration.

for infile in listing:

    #remove file extesnion.  Just a guess here.
    inputTab = infile[:-4]

    #check to see if it exists and delete it if so
    if arcpy.Exists(r"in_memory\\" + inputTab):
        arcpy.Delete_management(r"in_memory\" + inputTab)

    #copy the input table to the in_memory workspace and use it to perform the task
    arcpy.TableToTable_conversion(infile, r"in_memory\", inputTab)
    newfeature_shp = outshape[:-4]+str(index)+".shp"
    arcpy.XYToLine_management(inputTab, newfeature_shp, .....]
    index+=1
0 Kudos
DarrenWiens2
MVP Honored Contributor

The contents of 'listing' is a list of strings of the file names, not full paths, which is why it can't locate your csv. You can join the folder name to the file name using os.path.join(), or set the workspace environment to function as a default directory.