Python running a FOR loop but script seems to think the input workspace is empty?

1956
14
03-09-2020 08:50 AM
CarolineBanville
New Contributor

I'm writing a script tool to take a large data set select by location export and project it.  I cannot get the for loop to work and I am at a loss because the script runs without errors, but creates no outputs except for the buffer used for selection.  When debugging I've found that when I put the beginning part of the script before the for loop in there and have it try to print(Layers) it returns no values.  

See attached script.  Any help is greatly appreciated. 

0 Kudos
14 Replies
CarolineBanville
New Contributor

Thanks for your help once I fixed my inputs the tool ran but now I am getting this error, even though the output does exist and I'm not sure why it would not be supported. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

When errors relate to parameters, it is helpful to share the actual values stored in the variables being passed to the tool (and workspace if you are relying on relative paths).  I am guessing the issue is will out_name, but I am not sure since I don't know what string is in the variable.

0 Kudos
CarolineBanville
New Contributor

You are correct I'm having trouble with the paths, it seems to be defaulting to C:\Python27\ArcGIS10.7\ but the features are being created in my output workspace path.  I can't share my folder paths the data I'm working with is proprietary.  Right now the script is looking at a path where there is no output and I'm working on trying to re-path my variables so that out_name = Output_workspace + fc +"_SELECTION".  I'm having trouble with this because in the syntax for FeatureClassToFeatureClass includes Output_workspace so when I try to define out_name I get the path duplicated (i.e. C:\Data\Selection.shp\C:\Data\Selection.shp)

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

It might be worth searching out some blog posts or tutorials on using file paths in Python since you are struggling with it.  In the short term, you can try saving the Result object from Feature Class to Feature Class and passing that to project instead of trying to reconstruct the path yourself:

res = arcpy.FeatureClassToFeatureClass_conversion(out_layer, out_folder_path, out_name)
arcpy.Project_management(res, Coordinate, out_name2)
CarolineBanville
New Contributor

This did the trick.  Thank you. I will definitely look into using file paths.  

0 Kudos