emilharold

arcpy.Describe(lyr).FIDSet failure?

Discussion created by emilharold on May 28, 2014
Latest reply on May 28, 2014 by emilharold
I have writen a quick code just to improve my arcpy. The code uses a list of letters and then zooms around a California counties layer based on if their name contains each letter. However, it fails with 'i', 'v', and 'n'. 'W' and 'x' are the only letters it should bounce back. I am not sure why it does not detect a selection with 'i', 'v', and 'n'. The code is run in ArcMap through a toolbox. The code:
import arcpy
import time

mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd,"",df):
    if lyr.name == "state_county_2010":
        countylyr = lyr
Alphabet = ['q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m']
subset = ['e', 'r', 'i', 'o', 'a', 's', 'f', 'h', 'l', 'x', 'n', 'm']
for letter in Alphabet:
    arcpy.SelectLayerByAttribute_management(countylyr, "NEW_SELECTION", '"NAME10" LIKE \'%' + letter + '%\' OR "NAME10" LIKE \'%' + letter.upper() + "%'")
    if arcpy.Describe(countylyr).FIDSet:
        df.zoomToSelectedFeatures ()
        arcpy.AddMessage(letter)
        time.sleep(6)
        
    else:
        if letter in subset: 
            arcpy.AddMessage("No counties contain an " + letter + "!")
        else:
            arcpy.AddMessage("No counties contain a " + letter + "!")


The output:

q
No counties contain a w!
e
r
t
y
u
No counties contain an i!
o
p
a
s
d
f
g
h
j
k
l
z
No counties contain an x!
c
No counties contain a v!
b
No counties contain an n!
m

Any ideas?

Thx

Outcomes