#********************************************************************** # Description: # Tests if a field exists and outputs two booleans: # Exists - true if the field exists, false if it doesn't exist # Not_Exists - true if the field doesn't exist, false if it does exist # (the logical NOT of the first output). # # Arguments: # 0 - Table name # 1 - Field name # 2 - Exists (boolean - see above) # 3 - Not_Exists (boolean - see above) # # Created by: ESRI #********************************************************************** # Standard error handling - put everything in a try/except block # try: # Import system modules import sys, string, os, arcgisscripting # Create the Geoprocessor object gp = arcgisscripting.create() # Get input arguments - table name, field name # in_Table = gp.GetParameterAsText(0) in_Field = gp.GetParameterAsText(1) # First check that the table exists # if not gp.Exists(in_Table): raise Exception, "Input table does not exist" # Use the ListFields function to return a list of fields that matches # the name of in_Field. This is a wildcard match. Since in_Field is an # exact string (no wildcards like "*"), only one field should be returned, # exactly matching the input field name. # fields = gp.ListFields(in_Table, in_Field) # If ListFields returned anything, the Next operator will fetch the # field. We can use this as a Boolean condition. # field_found = fields.Next() # Branch depending on whether field found or not. Issue a # message, and then set our two output variables accordingly # if field_found: gp.AddMessage("Field %s found in %s" % (in_Field, in_Table)) gp.SetParameterAsText(2, "True") gp.SetParameterAsText(3, "False") else: gp.AddMessage("Field %s not found in %s" % (in_Field, in_Table)) gp.SetParameterAsText(2, "False") gp.SetParameterAsText(3, "True") # Handle script errors # except Exception, errMsg: # If we have messages of severity error (2), we assume a GP tool raised it, # so we'll output that. Otherwise, we assume we raised the error and the # information is in errMsg. # if gp.GetMessages(2): gp.AddError(GP.GetMessages(2)) else: gp.AddError(str(errMsg))
Solved! Go to Solution.
for fc in fcONElist: if not arcpy.Exists(r"path\two.gdb\dataset1\%s" % (fc)): print "not found: ", fc else: -- do the append --
Just how does
if arcpy.Exists(r"path\dataset\featureclass"):
not allow you to avoid an error?
Brett,
When you say "model searches for a featureclass" are you using an Iterator? If you use a FeatureClass iterator that will return all the FeatureClasses in a workspace, so missing ones are never an issue. Have a look at that, if that is not how you are searching for FeatureClasses the I suggest you upload an image of your model for us to understand.
Duncan
Your sub-model Input Riparian Point- is it your intention to "spit out" a single FeatureClass at a time or a bunch of FeatureClasses based upon your wild card. If it is meant to be a single FeatureClass I see no reason for it to be a sub model unless its doing some other complex stuff so you could probably do away with the collects tool. Normally the collects tool is the output parameter of a sub-model which you would link directly to the append tool. Have a look at this question I answered.
Try tweaking these first?
for fc in fcONElist: if not arcpy.Exists(r"path\two.gdb\dataset1\%s" % (fc)): print "not found: ", fc else: -- do the append --
as I understand this you have two GDBs (one.gdb and two.gdb)
each with, say, one data set
and each data set has a bunch of feature classes
one.gdb\dataset1\
has
fc1
fc2
fc3
fc4
fc5
fc6
and
two.gdb\dataset1\
has
fc1
fc2
fc4
fc5
fc6
(no fc3)
you want to append from gdb one to two
so you would use listfeatureclasses to list what is in one.gdb\dataset1\
call it fcONElist
loop through that list of fc names, testing for each in two.gdb\dataset1\
to wit:for fc in fcONElist: if not arcpy.Exists(r"path\two.gdb\dataset1\%s" % (fc)): print "not found: ", fc else: -- do the append --
I am sure it is more complex than this, but this is essentially the thing you need to do, eh?