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 <SPAN class="operator token">=</SPAN> <SPAN class="string token">"c:/temp"</SPAN>
env<SPAN class="punctuation token">.</SPAN>workspace <SPAN class="operator token">=</SPAN> dirpath
thelayer <SPAN class="operator token">=</SPAN> <SPAN class="string token">"mike4.lyr"</SPAN>
na_layer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>Layer<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>join<SPAN class="punctuation token">(</SPAN>dirpath<SPAN class="punctuation token">,</SPAN> thelayer<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Get the names of all the feature classes within the VRP layer.</SPAN>
sub_layer_names <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>na<SPAN class="punctuation token">.</SPAN>GetNAClassNames<SPAN class="punctuation token">(</SPAN>na_layer<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># Stores the layer names that we will use later</SPAN>
orders_layer_name <SPAN class="operator token">=</SPAN> sub_layer_names<SPAN class="punctuation token">[</SPAN><SPAN class="string token">'Orders'</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Get the orders sublayer</SPAN>
orders_sublayer <SPAN class="operator token">=</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>mapping<SPAN class="punctuation token">.</SPAN>ListLayers<SPAN class="punctuation token">(</SPAN>na_layer<SPAN class="punctuation token">,</SPAN> orders_layer_name<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="comment token"># Get the orders</SPAN>
<SPAN class="keyword token">with</SPAN> arcpy<SPAN class="punctuation token">.</SPAN>da<SPAN class="punctuation token">.</SPAN>SearchCursor<SPAN class="punctuation token">(</SPAN>in_table<SPAN class="operator token">=</SPAN>orders_sublayer<SPAN class="punctuation token">,</SPAN>
field_names<SPAN class="operator token">=</SPAN><SPAN class="punctuation token">(</SPAN><SPAN class="string token">'Name'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Description'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'RouteName'</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">'Sequence'</SPAN><SPAN class="punctuation token">,</SPAN>
<SPAN class="string token">'SHAPE@XY'</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN> <SPAN class="keyword token">as</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">for</SPAN> row <SPAN class="keyword token">in</SPAN> cursor<SPAN class="punctuation token">:</SPAN>
<SPAN class="keyword token">print</SPAN> <SPAN class="string token">"Name "</SPAN><SPAN class="punctuation token">,</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"RouteName "</SPAN><SPAN class="punctuation token">,</SPAN> row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">2</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Sequence "</SPAN><SPAN class="punctuation token">,</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">3</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="string token">"shape "</SPAN><SPAN class="punctuation token">,</SPAN>row<SPAN class="punctuation token">[</SPAN><SPAN class="number token">4</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
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?