[GIS] Make Route with Python and Network Analyst in ArcGIS Desktop giving ERROR 000192

arcgis-10.0arcmaparcpynetwork-analystroute

I'm having trouble debugging my python code to create a network analyst layer in ArcGIS 10.0. Basically when run from a script tool the code completes successfully without actually doing anything or returning any sort of useful information, and when run from the embedded python window in ArcGIS 10.0 i get the following error.

"Runtime error <class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid. ERROR 000192: Invalid value for Time Attribute Failed to execute (MakeVehicleRoutingProblemLayer)."

The script is supposed to solve the route and create a layer file for the output
Here is my code below:

#Import system modules
import arcpy
from arcpy import env

try:
    #Check out the Network Analyst extension license
    arcpy.CheckOutExtension("Network")

    #Set environment settings
    env.workspace = r'C:\Layout3.gdb'
    env.overwriteOutput = True

    #Set local variables
    inNetworkDataset = r'C:\Layout3.gdb\NtsFDS\NtsFDS_ND'
    outNALayerName = "TestResult"
    
    impedanceAttribute = "CABLE_COST"
    distanceAttribute = "TRAVEL_TIME"
    timeUntis = "Minutes"
    distanceUntis = "Meters"
    inOrders = r'\Layout3.gdb\NtsFDS\Orders'
    inDepots = r'C:\Layout3.gdb\NtsFDS\Depots'
    inRoutes = r'C:\Layout3.gdb\NtsFDS\Route'
    outLayerFile = env.workspace + outNALayerName + ".lyr"
        
    outNALayer = arcpy.na.MakeVehicleRoutingProblemLayer(inNetworkDataset, outNALayerName,
                                                         impedanceAttribute,
                                                         distanceAttribute)
    
    outNALayer = outNALayer.getOutput(0)

   
    subLayerNames = arcpy.na.GetNAClassNames(outNALayer)
    
    ordersLayerName = subLayerNames["Orders"]
    depotsLayerName = subLayerNames["Depots"]
    routesLayerName = subLayerNames["Routes"]
        
    candidateFields = arcpy.ListFields(inOrders)
    orderFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, ordersLayerName,
                                                       False, candidateFields)
    arcpy.na.AddLocations(outNALayer, ordersLayerName, inOrders, orderFieldMappings,"")

    
    depotFieldMappings = arcpy.na.NAClassFieldMappings(outNALayer, depotsLayerName)
    arcpy.na.AddLocations(outNALayer, depotsLayerName, inDepots, depotFieldMappings, "")
    
    arcpy.na.AddLocations(outNALayer, routesLayerName, inRoutes, "", "")
    
    #Solve the VRP layer
    arcpy.na.Solve(outNALayer)
    
    #Save the solved VRP layer as a layer file on disk with relative paths
    arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"RELATIVE")
    
    print "Script completed successfully"

except Exception as e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "An error occured on line %i" % tb.tb_lineno
    print str(e)

Best Answer

For this code to run you will need to upgrade to ArcGIS Desktop 10.1 because the ArcPy Network Analyst module (arcpy.na) was only introduced at that release - see What's new for geoprocessing in ArcGIS 10.1.

Related Question