AnsweredAssumed Answered

arcpy.Exists & arcpy.ListFeatureClasses and wildcards

Question asked by bradleyglennjones on Sep 9, 2015
Latest reply on Sep 10, 2015 by bradleyglennjones


I have a gdb with around 200 feature classes (waterlines).  I working on a tool that will add the featureclass desired base on an ID number. the featureclasses are named "WATERLINE_<ID NUMBER>_<NAME>".  Example: WATERLINE_123_SPRINGFIELD. Since the only parameter is entered as a 3 digit ID number (string)  I use a wildcard query with arcpy.ListFeatureClasses then use arcpy.Exists to add it to the map.  Some systems don't have waterline data.   This approach isn't working.  If I hardcode the featureclass name into arcpy.Exists it works.  Any ideas are appreciated.




# Import modules
import arcpy

# Set overwrite option
from arcpy import env
env.overwriteOutput = True

# Variables
pws = arcpy.GetParameterAsText(0)

waterlines = "WATERLINE_" + pws + "_*"
wl_layer = "Waterlines " + pws
wl_symb = r"G:\Source Water Protection\PWS_ID_Tool\WATERLINES.lyr"

# Add waterlines
env.workspace = r"G:\WATER_FACILITY\WATERLINES.gdb"
wlFclass = arcpy.ListFeatureClasses(waterlines)
arcpy.AddMessage(wlFclass)  # Print/message statement for results dialog box. Confirms wlFclass is there.
if arcpy.Exists(wlFclass):  # This where it fails.
    arcpy.AddMessage("Waterline data exist for this PWS.")
    arcpy.MakeFeatureLayer_management(waterlines, wl_layer)
    arcpy.ApplySymbologyFromLayer_management(wl_layer, wl_symb)
    newLayer = arcpy.mapping.Layer(wl_layer)
    arcpy.mapping.AddLayer(df, newLayer, "TOP")
    arcpy.AddWarning("No waterline data exist for this PWS.")




Tool results dialog box:

Executing: waterlinestest 465

Start Time: Wed Sep 09 10:36:53 2015

Running script waterlinestest...


No waterline data exist for this PWS.

Completed script waterlinestest...

Succeeded at Wed Sep 09 10:37:27 2015 (Elapsed Time: 33.95 seconds)

5 (Elapsed Time: 33.95 seconds)