This code will go to WATERLINES.gdb, go through the gdb to see if the fc exist (based on a wildcard query), then add the fc to the mxd as desired. My questions is if the fc doesn't exist, the "else" isn't met. That is, the warning "No Waterline data exist for the PWS." isn't added to the tool dialog. It just keeps running the rest of the code. I'm curious as to why?
Edit: I added more of the code.
# Import modules import arcpy import os # Set overwrite option from arcpy import env env.overwriteOutput = True pws = arcpy.GetParameterAsText(0) waterlines = "WATERLINE_" + pws + "_*" wl_layer = "Waterlines " + pws wl_symb = r"G:\Source Water Protection\PWS_ID_Tool\WATERLINES.lyr" # Set current mxd and dataframe. mxd = arcpy.mapping.MapDocument("CURRENT") df = arcpy.mapping.ListDataFrames(mxd, "") env.workspace = r"G:\WATER_FACILITY\WATERLINES.gdb" wlFclass = arcpy.ListFeatureClasses(waterlines) arcpy.AddMessage(wlFclass) for wl in wlFclass: wlPath = os.path.join(env.workspace,wl) if arcpy.Exists(wlPath): arcpy.AddMessage("Waterline data exist for this PWS.") arcpy.MakeFeatureLayer_management(wlPath, wl_layer) arcpy.ApplySymbologyFromLayer_management(wl_layer, wl_symb) newLayer = arcpy.mapping.Layer(wl_layer) arcpy.mapping.AddLayer(df, newLayer, "TOP") else: arcpy.AddWarning("No waterline data exist for this PWS.")
Edit: the wildcard creates a list of one fc and will only ever have one. to go from unicode to a "regular" string. then create the path for the one fc to use in the exist function. when I run the tool when a fc exist i get this messgae in the tool dialog:
Executing: waterlinestest 465 Start Time: Thu Sep 10 12:33:57 2015 Running script waterlinestest... [u'WATERLINE_465_CAW'] Waterline data exist for this PWS. Completed script waterlinestest... Succeeded at Thu Sep 10 12:34:45 2015 (Elapsed Time: 47.36 seconds)
if there is no fc: Executing: waterlinestest 492 Start Time: Thu Sep 10 12:41:26 2015 Running script waterlinestest...  Completed script waterlinestest... Succeeded at Thu Sep 10 12:42:13 2015 (Elapsed Time: 46.85 seconds)
So yes, even though the list created has nothing in it, it recognizes that it "exists".