Underscore

ModelBuilder and "if" condition

Discussion created by Underscore on Jul 26, 2012
Latest reply on Jul 26, 2012 by Hornbydd
I've searched, I've tried, I've tested, and I just can't get it.  I need help setting up the following in ModelBuilder:

Once I've performed a Search By Attribute task, I need to test if any rows were selected.  If so, I need to go to task B.  If not, I need to go to task C.  In my model I have a Calculate Value task (from ModelBuilder > Insert > Model Only Tools) and in the code I have this code, which I found on the ArcGIS - Desktop forum:

def hasSelection(layer):
    desc = arcpy.Describe(layer)
    fidset = desc.FIDSet
    if fidset =="":
        return "False"
    else:
        # A seelction exists so OK to execute
        return "True"


And in the Expression, I have hasSelection("%New Valves Selected%").  In my model, I made task B dependent on the result of the Calculate Value task, which I believe means it must return True.  But how do I make Task C dependent on the Calculate Value task being False?  This is what I don't get.

In the end, what I'm trying to avoid is doing a field calculate over the entire table if there are no records selected.

Outcomes