Directions using arcpy

1014
1
06-10-2014 09:53 AM
Highlighted
Occasional Contributor
Hello guys,
I am trying to use arcpy to generate directions for each route and save it for each day.  From help section this is what I have.

arcpy.na.Directions("Network Analysis Layer","TEXT","C:/temp/" + day1 + ".txt","Miles","REPORT_TIME","Minutes")



If I have an mxd which has a VRP Layer, how to best use arcpy to access it and loop to generate all directions.  I have my routes named as Day1, Day2, Day3 etc.,

Please help!!

Thanks in advance
-Pawan
ArcGIS Desktop 10.1 (Advanced)
Tags (2)
Reply
0 Kudos
1 Reply
Highlighted
Esri Regular Contributor
Hi!  If you have an MXD with several layer files saved in it already, you can access those layer files and put them into a list as follows:

#Get a list of all the layers in the map document
mxd = arcpy.mapping.MapDocument(mxd_path)
lyrs = arcpy.mapping.ListLayers(mxd)
#Filter the list to obtain only the network analyst layers
na_layers = [lyr for lyr in lyrs if lyr.isNetworkAnalystLayer]


You can then iterate through this list when generating directions.
If you're doing this from the python window in ArcMap instead of a standalone script, replace mxd_path in the script above with "CURRENT".
Reply
0 Kudos