Select to view content in your preferred language

Ignore errors instead of stopping in modelbuilder

5508
12
Jump to solution
03-04-2013 06:10 AM
TomMagdaleno
Frequent Contributor
I have a model which will pull 30 features from a database and a second model which will perform a feature class rename on these 30 different features.  This is done on a daily basis.  Sometimes one of the names will change or a feature won't be pulled in for some reason. 
  The problem is that when the rename model is running if it can't find a feature it will error the entire model instead of ignoring the error and skipping to the next feature to rename.  None of the processes have preconditions. 
Is their a way I can tell the model to ignore errors and move on if it can't find a feature?  A green error instead of a red one?
12 Replies
curtvprice
MVP Alum
I have a model which will pull 30 features from a database and a second model which will perform a feature class rename on these 30 different features.  This is done on a daily basis.  Sometimes one of the names will change or a feature won't be pulled in for some reason. 
  The problem is that when the rename model is running if it can't find a feature it will error the entire model instead of ignoring the error and skipping to the next feature to rename.  None of the processes have preconditions. 
Is their a way I can tell the model to ignore errors and move on if it can't find a feature?  A green error instead of a red one?



The only way I can think to do this is to use the Calculate Value tool to do the rename and have it return a message.  Calculate Value will print out the function results to geoprocessing messages as the model runs.

Of course this involves writing a small Python script:

I'm assuming you have two model elements "From FC" and "To FC" with the names.

Calculate Value tool

Expression: FCRename(r"%From FC%",r"%To FC%")

def FCRename(from,to):
  import arcpy
  try:
    arcpy.Rename_management(from,to)
    return "rename %s to %s success!" % (from,to)
  except:
    return "rename %s to %s failed" % (from,to)


(note, you can pass as many arguments to the function as you want, or put the dictionary and for loop inside the Calculate Value if you want.)
0 Kudos
curtvprice
MVP Alum
I have a model which will pull 30 features from a database and a second model which will perform a feature class rename on these 30 different features.  This is done on a daily basis.  Sometimes one of the names will change or a feature won't be pulled in for some reason. 
  The problem is that when the rename model is running if it can't find a feature it will error the entire model instead of ignoring the error and skipping to the next feature to rename.  None of the processes have preconditions. 
Is their a way I can tell the model to ignore errors and move on if it can't find a feature?  A green error instead of a red one?



The only way I can think to do this is to use the Calculate Value tool to do the rename and have it return a message.  Calculate Value will print out the function results to geoprocessing messages as the model runs.

Of course this involves writing a small Python script:

I'm assuming you have two model elements "From FC" and "To FC" with the names.

Calculate Value tool

Expression: FCRename(r"%From FC%",r"%To FC%")

def FCRename(from,to):
  import arcpy
  try:
    arcpy.Rename_management(from,to)
    return "rename %s to %s success!" % (from,to)
  except:
    return "rename %s to %s failed" % (from,to)



Note, you can pass as many arguments as you want. The "r" preceding the strings is important to make sure full path backslashes get interpreted right.
0 Kudos
TomMagdaleno
Frequent Contributor
Interesting...What error message were you getting?  I made a replica of your geodatabase in the exact same location  on my G: drive and executed the same code I posted above and it worked perfectly (Maybe I had your path name wrong?).  I have attached screenshots of the whole process below.

[ATTACH=CONFIG]22400[/ATTACH][ATTACH=CONFIG]22401[/ATTACH][ATTACH=CONFIG]22402[/ATTACH][ATTACH=CONFIG]22403[/ATTACH]


I got it.  Thank you Caleb.  User error on starting the python script, but it works now.
0 Kudos