0

The arcpy snippet below is intended to generate a list of technicians scheduled to work, and then generates a unique feature layer for each one's stops.

fcStops = "TaskRoute1016"
with arcpy.da.SearchCursor(fcStops, "AssignedEngineers") as cursor:
    TechList = sorted({row[0] for row in cursor})

print "Technicians today:"
for Technician in TechList:
    subsetSQL = "AssignedEngineers = '{}'".format(Technician)
    TechLayer = "Tech {}".format(Technician)
    arcpy.MakeFeatureLayer_management(fcStops, TechLayer, subsetSQL)
    print("  {}: {} stops".format(Technician, arcpy.GetCount_management(TechLayer).getOutput(0)))

It works perfectly once (selects just his stops, makes a feature layer, prints out the count), but only once. After the first iteration, I get:

Runtime error  Traceback (most recent call last):
File "<string>", line 5, 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.

The 000628 error says "The syntax used for the parameter is invalid for the parameter type" -- I'm not sure what's changing in my syntax, however, since the in_features variable should still be fcStops each time through the loop. If it's working once, why not multiple times?

I am running this in the Python window in ArcMap 10.2.1.

5
  • Do you have any NULL values in your AssignedEngineers field?
    – artwork21
    Commented Oct 16, 2014 at 12:13
  • No. Some of the names do have spaces, but that includes the first one (which executes without problems)
    – Erica
    Commented Oct 16, 2014 at 12:16
  • Wouldn't the loop try to create several layers for each technician if each technician has several tasks? Techlist should have duplicates removed. On the other hand, if that is the problem you would have error on parameter output layer already exists.
    – Stefan
    Commented Oct 16, 2014 at 13:08
  • TechList only has unique values.
    – Erica
    Commented Oct 16, 2014 at 13:17
  • 1
    I have a suspicion that you are encountering the same issue as in gis.stackexchange.com/questions/15800/…. I think this is an issue that I too have encountered and resolved using @Blah238's solution of deleting the feature layer before trying to recreate it.
    – PolyGeo
    Commented Oct 16, 2014 at 21:55

1 Answer 1

3

I'm not sure why, maybe a memory issue, but you need to use the full file path to the feature class you are creating the feature layer on. So for fcStops, put the full file path, not just the layer name from ArcMap.

I tested it on my machine, and it failed with the same error when I used the layer in the TOC, but worked fine when I used the full path.

fcStops = "FULL PATH\\TaskRoute1016"
with arcpy.da.SearchCursor(fcStops, "AssignedEngineers") as cursor:
    TechList = sorted({row[0] for row in cursor})

print "Technicians today:"
for Technician in TechList:
    subsetSQL = "AssignedEngineers = '{}'".format(Technician)
    TechLayer = "Tech {}".format(Technician)
    arcpy.MakeFeatureLayer_management(fcStops, TechLayer, subsetSQL)
    print("  {}: {} stops".format(Technician, arcpy.GetCount_management(TechLayer).getOutput(0)))
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.