mjoselyn

Route feature class not respecting selected features

Discussion created by mjoselyn on May 9, 2011
Greetings,
I have a python script tool that runs fine against all features in a Route Event Layer.
However, if I graphically select a subset of features, it iterates through the first record and not the rest.

If I export the Route Event Layer to a stand-alone feature class in a file geodatabase it works fine against a selected set of features, iterating through (SUMing) the entire set.

Why won't the script respect, or properly iterate through, a selected set of records in a Route Event Layer?

# Name: Sum_Measures.py
# Import system modules
import arcpy
from arcpy

# Define attribute fields and desired statistcal metrics
statsFields = [["FROM_FT", "SUM"],["TO_FT", "SUM"]]

inRoads = arcpy.GetParameterAsText(0) #Route Feature Class
outStatsTable = arcpy.GetParameterAsText(1) # Table to be created with summed lengths

# Execute Statistics to get the area of each vegetation type within
arcpy.Statistics_analysis(inRoads, outStatsTable, statsFields)

# Create a search cursor 
rows = arcpy.SearchCursor(outStatsTable)
fields = arcpy.ListFields(outStatsTable)

for row in rows:
    for field in fields:
        if field.name == "SUM_FROM_FT":
            arcpy.AddMessage(str(row.getValue(field.name)))
            FROM_M = row.getValue(field.name)
        elif field.name == "SUM_TO_FT":
            arcpy.AddMessage(str(row.getValue(field.name)))
            TO_M = row.getValue(field.name)

TOT_DIST_MI = ((TO_M - FROM_M) / 5280)
arcpy.AddMessage("Total Distance = " + str(TOT_DIST_MI) + " miles")

Outcomes