Model Builder Delete Feature Class problem

4765
6
04-20-2012 07:37 AM
BrentHoskisson
Occasional Contributor III
How do I add the Delete tool to my Model if the feature class doesn't exist?  It will be unknown at runtime whether the feature class will exist and I want it to delete the feature class if it does exist.  However it seems that I can only add the Delete tool if the feature class exists.  How do you experts get around this "bug/feature"?

Thanks
0 Kudos
6 Replies
ShitijMehta
Esri Regular Contributor
You can put in some if-then-else logic in your model using either the Calculate Value tool or a script tool.

Check this series of blogs:

If you are stuck at "if" �?? Part 1
If you are stuck at "if" �?? Part 2 �?? Example of using Script tool to create branches using if-els...
If you are stuck at "if" �?? Part 3 �?? Does Extension Exists model example
If you are stuck at "if" �?? Part 4 �?? Does Selection Exists model example


Create a dummy feature class in the place where your feature class could exists or not (location) such the your feature class exists. Run the model once based on this blog
If you are stuck at "if" �?? Part 1. This blog has an example for your case.

Once your model validates and runs for your dummy feature class. You can save the model and run it from its tool dialog. You will have to experiment a little with your model as I do not really know besides the delete what are the other tools in your model.
0 Kudos
BrentHoskisson
Occasional Contributor III
The "if" is not the problem.  I can already say whether the Feature Class exists or not, but that doesn't help me at Design Time when I can't even add the tool becaus the Feature Class doesn't exist.  Is there an "If" that works at design time and lets you add tools without some valid arguments?
0 Kudos
ShitijMehta
Esri Regular Contributor
Hi brenth,

Please can you share your model or a snapshot of your model so see what you are doing? You are trying to connect the output of which tool to the delete tool?
0 Kudos
BrentHoskisson
Occasional Contributor III
I attached the simplest model that breaks.  Here is the code inside "Conditional Delete".  It will not even start if the feature class doesn't exist, but the whole point of the script is to see if the feature class exists first.


import sys, os, arcpy

# Get the input from the model
InputFC = arcpy.GetParameterAsText(0)


# Statement to check the existence of the feature class
if arcpy.Exists(InputFC):
    arcpy.AddMessage("Feature Class Exists and will be deleted!")
    arcpy.Delete_management(InputFC, "FeatureClass")
arcpy.SetParameterAsText(1,"True")
0 Kudos
BrentHoskisson
Occasional Contributor III

Create a dummy feature class in the place where your feature class could exists or not (location) such the your feature class exists. Run the model once based on this blog
If you are stuck at "if" �?? Part 1. This blog has an example for your case.


Off topic.  Have you tested your "If Feature Class Exists" on this blog with SDE layers?  I get false even if the feature class does exist (my other similar scripts return true with the same info).
0 Kudos
NobbirAhmed
Esri Regular Contributor
One way to get it done is to make the input parameter of the script tool optional and make the output parameter derived.
0 Kudos