Issue with Copy Features in Python

Discussion created by ryank11 on Jun 21, 2014
Latest reply on Aug 8, 2014 by xander_bakker
I'm fairly new to writing scripts in python.  I'm creating one to take a feature class of about 100 points and turn it into individual points then run a cost path analysis on each of them.  The cost rasters and backlink rasters are already created.

The problem with the script is that it will create the individual points, but they won't work with the rest of the script that creates the cost paths while it's running.  If the script stops running and restarts with the section of code commented out to create the points, it will run the cost paths on the points it created the last time it ran.

     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

I'm pretty sure the problem is in Copy Features.  The script will recognize the features exist, but gives this error message:

arcgisscripting.ExecuteError: ERROR 010045: COSTPATH: The number of FROM cells is 0.
ERROR 010067: Error in executing grid expression.

Again, if I run it with the costpath lines commented out, it will run fine.  If I rerun it with the lines making the points commented out, it will run fine and create the costpaths.

The whole thing has to run in one go, so I can't just create 2 separate scripts and run them one at a time unfortunately.

Any suggestions on how to solve this problem?