AnsweredAssumed Answered

Error on Make Feature Layer for looping over selected attributes

Question asked by iamurray on May 29, 2014
Latest reply on Jun 5, 2014 by Wayne_Whitley
I've ran into a bit of a unique problem, which for the life of me I cannot get debugged.

I have a two geodatabase feature classes, one with customer regions, and one with zip codes.  I'm iterating through each region and selecting each zip code within and writing the region with zip codes to a csv.  This works flawlessly the first loop through, but I run into an error on the Make Featuer Layer on subsequent iterations.  I am entering in the code through the iterative python window, and both fcs are in the TOC, and neither Feature Layer exists prior to running the code. 

 import arcpy from arcpy import env env.overwriteOutput = 1  arcpy.env.overwriteOutput = True #env.workspace = r"C:\Users\iamurray\Desktop\Ray\Zip Code\ZipCodes.gdb" output = open(r"C:\Users\iamurray\Desktop\Output.csv", "w")  count = 1  for item in range(1,163,1): # there are 162 features to be selected,      input1 = "TVA_Distributors"     input2 = "TVA_PSA_Zips"     outlayer1 = "TVA_Distributors_Layer"     outlayer2 = "TVA_PSA_Zips_Layer"     print count     #arcpy.SelectLayerByAttribute_management(input1, "NEW_SELECTION", [OBJECTID] =  + str(count))     arcpy.MakeFeatureLayer_management(input1, outlayer1, 'OBJECTID = ' + str(count)) #works on count = 1 but not on count = 2 and subsequent           cursor = arcpy.da.SearchCursor(outlayer1, ["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", outlayer1, "", "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")     count += 1     print "The Current number of Distributors Processed is " + str(count - 1)     arcpy.Delete_management(outlayer1)     arcpy.Delete_management(outlayer2)     del row     del cursor output.close() 

These are the results I am getting
Warren RECC
The Current number of Distributors Processed is 1
Runtime error  Traceback (most recent call last):   File "<string>", line 20, in <module>   File "c:\program files (x86)\arcgis\desktop10.1\arcpy\arcpy\", 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.

It works fine the first time, because it reaches the print count on the second run through successfully.  At first I thought it was an issue with the overwrite, but I've set both of those to allow overwrite and deleted the intermediate layers prior to the next MakeFeatureLayer.  The input and outputs should not change just the expression, which should still be valid each time, since each has a unique OBJECTID number.  I simply can't see what is wrong with the tool parameters that would cause this to crash on the subsequent loops. 

If anyone has some insight into this, I would be most appreciative, I'm using ArcGIS 10.1 SP1.

EDIT: There are no syntax errors if you find any, its a result of me copying the code over.