Okay so not sure why this fixed it but it did.Originally I was using feature classes in a gdb, and I got this error on time second time through the for-loop.Runtime error Traceback (most recent call last): File "<string>", line 20, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer raise e ExecuteError: ERROR 000622: Failed to execute (Make Feature Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_features. I merely converted them to shapefiles and brought them into arcmap instead of the feature classes from a GDB and it worked after switching the selecting field name. There must be something about the gdb that puts some sort of lock it on for subsequent iterations where it does not for shapefiles.this is the code that ended up working
import arcpy
from arcpy import env
env.overwriteOutput = 1
arcpy.env.overwriteOutput = True
output = open(r"C:\Users\iamurray\Desktop\Output.csv", "w")
input1 = "TVA_Distributors"
input2 = "TVA_PSA_Zips"
outlayer2 = "TVA_PSA_Zips_Layer"
for item in range(0,162,1):
print item
arcpy.MakeFeatureLayer_management(input1, "TVA_Distributors" + str(item), "\"FID\" = " + str(item))
cursor = arcpy.da.SearchCursor("TVA_Distributors" + str(item), ["DISTRIBU_1"])
for row in cursor:
output.write(str(row[0])+ "\n")
print row[0]
del cursor
arcpy.SelectLayerByLocation_management(input2, "INTERSECT", "TVA_Distributors" + str(item), "", "NEW_SELECTION")
# Process: Make Feature Layer (2)
arcpy.MakeFeatureLayer_management(input2, outlayer2)
field = "ZIP"
cursor = arcpy.SearchCursor(outlayer2)
for row in cursor:
output.write(str(row.getValue(field))+ "\n")
print "The Current number of Distributors Processed is " + str(item)
arcpy.Delete_management("TVA_Distributors" + str(item))
arcpy.Delete_management(outlayer2)
del row
del cursor
output.close()
This is the code I used for the gdb feature classes which failed, the only changes made were changing FID to ObjectID and the range from 0,162,1 to 1,163,1
import arcpy
from arcpy import env
env.overwriteOutput = 1
arcpy.env.overwriteOutput = True
output = open(r"C:\Users\iamurray\Desktop\Output.csv", "w")
input1 = "TVA_Distributors"
input2 = "TVA_PSA_Zips"
outlayer2 = "TVA_PSA_Zips_Layer"
for item in range(1,163,1):
print item
arcpy.MakeFeatureLayer_management(input1, "TVA_Distributors" + str(item), "\"OBJECTID\" = " + str(item))
cursor = arcpy.da.SearchCursor("TVA_Distributors" + str(item), ["DISTRIBU_1"])
for row in cursor:
output.write(str(row[0])+ "\n")
print row[0]
del cursor
# Process: Select Layer By Location
arcpy.SelectLayerByLocation_management(input2, "INTERSECT", "TVA_Distributors" + str(item), "", "NEW_SELECTION")
# Process: Make Feature Layer (2)
arcpy.MakeFeatureLayer_management(input2, outlayer2)
field = "ZIP"
cursor = arcpy.SearchCursor(outlayer2)
for row in cursor:
output.write(str(row.getValue(field))+ "\n")
print "The Current number of Distributors Processed is " + str(item)
arcpy.Delete_management("TVA_Distributors" + str(item))
arcpy.Delete_management(outlayer2)
del row
del cursor
output.close()
And this was the error I was gettingRuntime error Traceback (most recent call last): File "<string>", line 20, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer raise e ExecuteError: ERROR 000622: Failed to execute (Make Feature Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_features. I'm really curious why using the interactive python window that shapefiles would work and gdb feature classes would not. Both had the same names. The syntax had to be correct, because for the feature class code it would run the first iteration, but throw that error on the subsequent ones. With the shapefiles it ran through without a hiccup. In both instances the files were the only items in the TOC.When I attempt to run it outside of ArcGIS with env.workspace set to the gdb, or the file path hardcoded, it crashes with ERROR 000386.Traceback (most recent call last): File "C:\Users\iamurray\Desktop\Zipcode.py", line 31, in <module> arcpy.SelectLayerByLocation_management(input2, "INTERSECT", "TVA_Distributors" + str(item), "", "NEW_SELECTION") File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6559, in SelectLayerByLocation raise eExecuteError: Failed to execute. Parameters are not valid.ERROR 000368: Invalid input data.Failed to execute (SelectLayerByLocation).>>> Similarly when I run it in the interactive window with env.workspace set or the file paths hard-coded it crashes with same errorIf I run it with just the file names with both feature classes brought into the dataframe it runs through the first time successfully and crashes with the error code from my first post.Runtime error Traceback (most recent call last): File "<string>", line 20, in <module> File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\management.py", line 5748, in MakeFeatureLayer raise e ExecuteError: ERROR 000622: Failed to execute (Make Feature Layer). Parameters are not valid. ERROR 000628: Cannot set input into parameter in_features. When I try to run it with the shapefiles using env.workspace set to their folder location it crashes, since the input must be a feature layer or feature class.So I'm really curious how my only solution to this was to bring the shapefiles into the TOC as feature layers and run the program in the interactive python window using only that workspace.Wayne and Adam,thank you for your attempts to help on this, it did get my brain thinking in different ways and eventually got me to a solution.