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

1946
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
DanPatterson_Retired
MVP Emeritus

between lines 25 and 26, add a 

print("Layers found {}".format(Input_workspace))

If you get nothing, then the input workspace isn't any good, or it isn't a full path.

Also add a 

print("Layer name {}".format(Layer.name))

on line 26.5

Also

/blogs/dan_patterson/2016/08/14/script-formatting 

so people can copy and paste your code and have it formatted properly.  Screen grabs can be use.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

ListFeatureClasses—Help | Documentation is designed to have the workspace already set:

The workspace environment must be set before using several of the list functions, including ListDatasets, ListFeatureClasses, ListFiles, ListRasters, ListTables, and ListWorkspaces.

For starters, you have to set the workspace.  Secondly, passing a workspace as a wildcard search will likely result in nothing being returned even if the workspace is set.

CarolineBanville
New Contributor

I had a feeling this was the problem, I need to have multiple workspaces in the script and it's causing issues I think I need a larger for loop to go through the workspaces instead of setting up the for loop for one workspace.  Thanks for pointing it out.

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

Most, if not all, geoprocessing tools accept full paths to data sets, and I strongly encourage passing/using full paths instead of relying on the workspace being set.

0 Kudos
CarolineBanville
New Contributor

I've made the following correction to list through multiple workspaces but the arcpy.MakeFeatureLayer is not running it's erroring out at the project step because there are no inputs.  

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

You state:

the arcpy.MakeFeatureLayer is not running it's erroring out at the project step because there are no inputs. 

So is Make Feature Layer not working or Project?  It is always helpful to paste the error and full traceback to avoid confusion like this on what exactly is generating the error.

0 Kudos
CarolineBanville
New Contributor

Sorry I can clarify, above is the error I am getting but also when I check my results folder it doesn't appear to be creating any outputs.  Since Project is the last function I thought the error was coming from a lack of inputs from Make Feature Layer and Select Layer by Location appear to not be running. 

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The error is in your output coordinate system.  So, what is it exactly? 

0 Kudos
by Anonymous User
Not applicable

Hi Caroline, 
On line 38 where you're calling arcpy.Project_managment() try switching the order of your second and third arguments. 

Arcpy is expecting input dataset, followed by output dataset, then coordinate system (see: Project—Data Management toolbox | Documentation ). While the script is currently specifying input dataset, followed by coordinate system, then output dataset. The error 'cannot set input into parameter out_coor_system is basically complaining that it can't figure out how to interpret the contents of the out_name2 variable as a coordinate system. 

What we should end up with on line 38 will be

arpcy.Project_management(out_name, out_name2, Coordinate)

If we still have issues with the call to Project_management after making this change, we'll likely need to take a look at what input is being provided on line 18 with Coordinate = arcpy.GetParameterAsText(7)