I'm creating a custom python script, and having trouble calling the script on a specific route within a layer

routekeyfield = 'route_ID'
routename = 'I95 NB'

routeslayer = "C:\\Projects\\\\Routes2017.mdb\\Routes"
# table = arcpy.CreateTable_management("in_memory", "stripMaps")
#memoryFeature = "in_memory\\stripMaps"
memoryFeature = "c:\\path\\stripmaps.mdb\stripmapsstuff"

#query the routes layer for the specific route
fields = ["SHAPE", routekeyfield]
whereclause = routekeyfield + " = '" + routename + "'"
with arcpy.da.SearchCursor(routeslayer, fields) as cursor:
    for row in cursor:
        arcpy.StripMapIndexFeatures_cartography(in_features=row, out_feature_class=memoryFeature, use_page_unit="NO_USEPAGEUNIT", scale=str(currentextentscale), length_along_line=str(currentextentwidth) + " Meters", length_perpendicular_to_line=str(currentextentscale) + " Meters", page_orientation="HORIZONTAL", overlap_percentage="10", starting_page_number="1", direction_type="WE_NS")

I'm not exactly sure how to filter the layer for a specfic route. Note, I'm using this script from a standalone script. Anybody have some ideas? `


You're almost there. It seems like you've started to build the whereclause for your SearchCursor, but didn't implement it.

Change your SearchCursor line to the following:

with arcpy.da.SearchCursor(routeslayer, fields, where_clause = whereclause) as cursor:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.