3

What I would like to do is create a script that checks the existence of a feature class and, depending whether it does or not does, skip to different process. This would need to be implemented in Modelbuilder so if there is a tool I have not utilized (instead of a script), point me in the right direction!

I am a complete noob when it comes to Python, so the simpler the better!

4
  • here's a good place to start resources.arcgis.com/en/help/main/10.1/index.html#//…
    – mr.adam
    Feb 3 '15 at 15:54
  • Essentially, what I would like to do is create a Python script that branches (if the feature dataset exists, to go straight to a Select by Location process and if it doesn't to complete the conversion from a shapefile to geodatabase). I am a complete noob to Python so please make it simple for me! Feb 3 '15 at 19:37
  • 1
    ah, that's a bit different, it would be good if you could update the question to include your desire for a python script. what you're asking for is not too difficult, but the more details the better.
    – mr.adam
    Feb 3 '15 at 19:56
  • So you want to prepare it in Model Builder and then export it to a script? Or is a script sufficient? And what exatly do you mean by checking if a file exists? Will you apply the sript to a folder and see if anything is in it first of all? Because any other way, you would provide a file, and in that case it would exist anyways. Feb 4 '15 at 11:48
4

There is an Esri blog post that describes the technique for doing this in detail called If you are stuck at "if" – Part 1:

Part 1 – Gives examples of quick and dirty ways of using the Calculate Value tool to create branches using if statements in a model.

In your case you want to check for the existence of a feature class rather than a product license so I would use this as the code for your Feature Class exists Python script tool:

Expression

x("%FCToCheck%")

Code Block

def x(FCToCheck):
import arcpy
if arcpy.Exists(FCToCheck):
    return "true"
else:
    return "false"

and this as the code for your Feature Class does not exist Python script tool:

Expression;

x("%ProductToCheck%")

Code Block

def x(FCToCheck):
import arcpy
if arcpy.Exists(FCToCheck):
    return "false"
else:
    return "true"

Personally, I far prefer to implement such branching using pure Python/ArcPy rather than having ModelBuilder in the mix.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.