Using ArcMap 10.2.2, I created a simple Network Analyst Vehicle Routing problem with 8 points, and 1 depot, and solved it. I then saved the layer to a ".lyr" file and used the program below to output information about the points I had added:
dirpath = "c:/temp"
env.workspace = dirpath
thelayer = "mike4.lyr"
na_layer = arcpy.mapping.Layer(os.path.join(dirpath, thelayer))
# Get the names of all the feature classes within the VRP layer.
sub_layer_names = arcpy.na.GetNAClassNames(na_layer)
# Stores the layer names that we will use later
orders_layer_name = sub_layer_names['Orders']
# Get the orders sublayer
orders_sublayer = arcpy.mapping.ListLayers(na_layer, orders_layer_name)
# Get the orders
'SHAPE@XY')) as cursor:
for row in cursor:
print "Name ", row, "RouteName ", row, "Sequence ",row,"shape ",row
The problem I was having is that it was only printing ONE of my 8 points I had created. I then discovered that when I saved the layer file in ArcMap, I had selected that single point. If I selected 4 of the 8 points, and saved, it only printed those 4 points.
So my question is, what is the right way to alter the above code so that it will print all the Orders independent of whether the layer file was saved and had some of the orders selected or not?