I want to calculate a route consisting of 4 points with a script tool and save the results to disk. I need the route to appear as layer on ArcCatalog for continuing working with it (modification of its attribute table). The script tool completes successfully but no output is saved. So, I tried to add the Save To Layer File tool.
I receive the following error message:
File "C:\Users\Manu\Desktop\SS 2015\Analyse mit GI-Technologien\Abgabe\gruppe1\Teil1_240915.py", line 84, in arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"","CURRENT") File "c:\program files (x86)\arcgis\desktop10.2\arcpy\arcpy\management.py", line 6640, in SaveToLayerFile raise e
ExecuteError: ERROR 999999: Error executing function. Failed to execute (SaveToLayerFile).
This is my code:
#Create a new Route layer.
outRouteResultObject=arcpy.na.MakeRouteLayer(in_network_dataset,out_network_analysis_layer=outNALayerName,impedance_attribute=impedanceAttribute,find_best_order="USE_INPUT_ORDER",accumulate_attribute_name=["Length"],output_path_shape="TRUE_LINES_WITH_MEASURES")
#Get the layer object from the result object. The route layer can now be referenced using the layer object.
outNALayer=outRouteResultObject.getOutput(0)
#Get the names of all the sublayers within the route layer.
subLayerNames=arcpy.na.GetNAClassNames(outNALayer)
#Store the layer names that we will use later
stopsLayerName=subLayerNames["Stops"]
routeLayerName=subLayerNames["Routes"]
fieldMappings=arcpy.na.NAClassFieldMappings(outNALayer,stopsLayerName)
fieldMappings["RouteName"].mappedFieldName="stopover"
arcpy.na.AddLocations(outNALayer,stopsLayerName,"Stations",fieldMappings,"","Order","SNAP")
arcpy.na.Solve(outNALayer)
arcpy.management.SaveToLayerFile(outNALayer,outLayerFile,"","CURRENT")