AnsweredAssumed Answered

SearchCursor dependent on selected items?

Question asked by irvlustig on Sep 23, 2016
Latest reply on Sep 23, 2016 by irvlustig

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 =

# 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)[0]

# Get the orders
with arcpy.da.SearchCursor(in_table=orders_sublayer,
                     'SHAPE@XY')) as cursor:
    for row in cursor:
        print "Name ", row[0], "RouteName ", row[2], "Sequence ",row[3],"shape ",row[4]



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?