i = 1
number_of_points = int(arcpy.GetCount_management("route_one_points").getOutput(0))
print number_of_points
while i <= number_of_points:
print "testing"
print i
pointname = "route_one_point" + str(i)
arcpy.MakeFeatureLayer_management("route_one_points", pointname)
arcpy.SelectLayerByAttribute_management(pointname, "NEW_SELECTION", "OBJECTID = %s" % i)
arcpy.CopyFeatures_management("route_one_point" + str(i), "route_one_point" + str(i))
print pointname
outCostPath = arcpy.sa.CostPath(pointname, "route_one_cost", "route_one_backlink")
outCostPath.save("route_one_point" + str(i) + "_path")
i += 1
Both your original feature layer you create and your feature class have the same name, pointname ( or "route_one_point" + str(i)).
I'm assuming you want to use your feature class you created, so perhaps give your feature class a different name than your feature layer and run again(say pointname + "fc"). It might be trying to run the tool off feature layer you made first, instead of the feature class with only one point.
Also, since you already made a variable for pointname = "route_one_point" + str(i), hardcoding in "route_one_point" + str(i) again and again is a bit wasteful.
There is still a potential risk in this code. If you loop through the points to create a where clause with your Object ID, you assume that the values of the ObjectID is a range without gaps in its values. This might be the case, but if you edit the featureclass and delete a feature, it will no longer be the case.
To create a more stable way you could use something like:
fc_pnts = "C:/Users/Ryan/Documents/arcgis_folder/sitetwoworkarea.gdb/route_one_points"
# determine the ObjectID field name
fld_oid = arcpy.Describe(fc_pnts).OIDFieldName
# make a list of all the ObjectID's in the featureclass
lst_oid = [row[0] for row in arcpy.da.SeachCursor(fc_pnts, ("OID@"))]
# loop through oid's and create the where clause
for oid in lst_oid:
where = "{0} = {1}".format(arcpy.AddFieldDelimiters(fc_pnts, fld_oid), oid)
That worked, Ian. I can't believe it, it seems kinda obvious, but I've been looking at this off and on for 2 months, two people I go to school with have been looking at it, and 4 people on here did. And like almost every huge problem, it turns out to be something obvious. ![]()
Another reason to use variables more effectively. If you had used your variable in ever place you spelled out its value, I bet it would have been caught a little sooner, since it would have been more apparent ot the eye that you were using the same string for each.
Glad you got it working properly.