agolservices.FindRoutes not working? (Messages say "Successful", but output won't save)

421
2
08-29-2023 01:55 PM
MaryGraceMcClellan
New Contributor III

Hello, I am trying to loop through two layers (stops and barriers), and select from each using a common ID. Once the appropriate stops and barriers are selected, I would like to run the Find Routes tool using AGOL's routing service. I am prepared to have the script use credits and I have ensured I have enough, so the issue is not related to that as far as I know.

I am importing the Route module like so: 

gis = GIS("Pro") # I am logged into my organization through ArcGIS Pro 

route_service = "https://logistics.arcgis.com/arcgis/services;World/Route;"
arcpy.ImportToolbox(route_service)

 

I then loop through everything using the following code: 

 

# Create stops layer
arcpy.MakeFeatureLayer_management(start_end_points,"stops_lyr")

## Create bridge barriers
arcpy.analysis.Buffer(bridges, barriers, "10 Meters", "FULL", "ROUND", "NONE")
arcpy.MakeFeatureLayer_management(barriers,"barriers_lyr")

bridge_list = [55, 37, 12]
for b in bridge_list:
    # Select relevant stops and barriers for routes
    barrier_query = """"ORIG_FID" = {}""".format(b)
    stops_query = """Bridge_OID = '{}'""".format(b)
    arcpy.management.SelectLayerByAttribute("barriers_lyr", "NEW_SELECTION", barrier_query)
    arcpy.management.SelectLayerByAttribute("stops_lyr", "NEW_SELECTION", stops_query)
    # Run Route tool
    result = arcpy.agolservices.FindRoutes("stops_lyr", "Minutes", "NorthAmerica", Return_to_Start=True,
                                            Polygon_Barriers = "barriers_lyr", Use_Hierarchy=True, Travel_Mode="Custom",                                                    Output_Format="Feature Set")
   

    result.getOutput(1).save(output_routes)

 

The above results in the following error: 

 

RuntimeError: ResultObject: Error in getting output

 

My credit usage is not going down so I don't think the tool is even running. When I call results.status, I get "4" as a result, and the messages all say that it was a success. 

0 Kudos
2 Replies
frobertsmaf
New Contributor III

Any luck at getting this figured out, I am having similar issues with using the 

arcpy.agolservices
0 Kudos
MaryGraceMcClellan
New Contributor III

Hi, sorry for the delay in responding! I guess I don't get notifications. I ended up using 

 

arcpy.na.AddLocations()

 

I input my network and points, etc, then:

 

result = arcpy.na.Solve("Route", "SKIP", "TERMINATE", None, '') 

 

 

Then, to access the routes layer, I looped through `result` like this: 

 

if result.status == 4:
    for x in result.getOutput(0).listLayers():
        if x.name == "Routes":
            [analyze route here]

 

 

I hope this helps! 

 

0 Kudos