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()
Solved! Go to Solution.
import arcpy, os from arcpy import env env.overwriteOutput = True env.addOutputsToMap = True env.workspace = r"C:\Users\whitley-wayne\Documents\ArcGIS\Default.gdb" # the following line results in 000622 and 000628 failures on the 2nd iteration... #input1 = 'Export_Output' # so instead set your input var to a fully qualified pathname to your gdb source input1 = os.path.join(env.workspace, 'Export_Output') print '\nusing a fully-qualified pathname to the fc:\n{0}\n'.format(input1) # sample of 2 outputs, added to the map only for testing purposes outlayer1 = "TVA_Distributors_Layer" outlayer2 = "TVA_PSA_Zips_Layer" # if querying OID, make sure you're querying the correct one objID = arcpy.Describe(input1).OIDFieldName print 'using the true OID field name, {0}\n'.format(objID) for i in range(2): outlayer = 'outlayer{0}'.format(str(i + 1)) qry = '{0} = {1}'.format(objID, str(i + 1)) print 'this is the query: {0}'.format(qry) arcpy.MakeFeatureLayer_management(input1, outlayer, qry) print '...check the map for {0}\n'.format(outlayer) print 'done.'
using the true OID field name, OBJECTID_1 this is the query: OBJECTID_1 = 1 ...check the map for outlayer1 this is the query: OBJECTID_1 = 2 Runtime error Traceback (most recent call last): File "<string>", line 26, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6043, 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.
using a fully-qualified pathname to the fc: C:\Users\whitley-wayne\Documents\ArcGIS\Default.gdb\Export_Output using the true OID field name, OBJECTID_1 this is the query: OBJECTID_1 = 1 ...check the map for outlayer1 this is the query: OBJECTID_1 = 2 ...check the map for outlayer2 done.
'"fieldname" = \'' + value + "'" #make sure value is a string
'"fieldname" = ' + value #make sure value is a string (though a digit, of course)
if arcpy.Exists(outlayer1): arcpy.management.Delete(outlayer1)
import arcpy from arcpy import env env.overwriteOutput = True env.addOutputsToMap = True env.workspace = r"C:\Users\iamurray\Desktop\Ray\Zip Code\ZipCodes.gdb" # set your input var to a sample input fc name in your source, ZipCodes.gdb input1 = 'your gdb fc name here' # sample of 2 outputs, added to the map only for testing purposes outlayer1 = "TVA_Distributors_Layer" outlayer2 = "TVA_PSA_Zips_Layer" for i in range(2): arcpy.MakeFeatureLayer_management(input1, outlayer + str(i + 1), 'OBJECTID = ' + str(count)) print '...check the map for {0}'.format(outlayer + str(i + 1)) print 'done.'
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()
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()
import arcpy, os from arcpy import env env.overwriteOutput = True env.addOutputsToMap = True env.workspace = r"C:\Users\whitley-wayne\Documents\ArcGIS\Default.gdb" # the following line results in 000622 and 000628 failures on the 2nd iteration... #input1 = 'Export_Output' # so instead set your input var to a fully qualified pathname to your gdb source input1 = os.path.join(env.workspace, 'Export_Output') print '\nusing a fully-qualified pathname to the fc:\n{0}\n'.format(input1) # sample of 2 outputs, added to the map only for testing purposes outlayer1 = "TVA_Distributors_Layer" outlayer2 = "TVA_PSA_Zips_Layer" # if querying OID, make sure you're querying the correct one objID = arcpy.Describe(input1).OIDFieldName print 'using the true OID field name, {0}\n'.format(objID) for i in range(2): outlayer = 'outlayer{0}'.format(str(i + 1)) qry = '{0} = {1}'.format(objID, str(i + 1)) print 'this is the query: {0}'.format(qry) arcpy.MakeFeatureLayer_management(input1, outlayer, qry) print '...check the map for {0}\n'.format(outlayer) print 'done.'
using the true OID field name, OBJECTID_1 this is the query: OBJECTID_1 = 1 ...check the map for outlayer1 this is the query: OBJECTID_1 = 2 Runtime error Traceback (most recent call last): File "<string>", line 26, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.2\arcpy\arcpy\management.py", line 6043, 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.
using a fully-qualified pathname to the fc: C:\Users\whitley-wayne\Documents\ArcGIS\Default.gdb\Export_Output using the true OID field name, OBJECTID_1 this is the query: OBJECTID_1 = 1 ...check the map for outlayer1 this is the query: OBJECTID_1 = 2 ...check the map for outlayer2 done.