I'm working on a model that will create different buffers for different selections. So I'm using Make Feature Layer and adding an expression to select a subset of features and then using the buffer tool on that subset. But there may be times when a selection doesn't return any features, in which case I wouldn't want to run the buffer. Is there a way in ModelBuilder to test whether or not any features are selected and only run the subsequent step if there are?

Alternatively I could export to a Python script and handle this testing there but I'm not quite sure how to accomplish this in Python either.

2 Answers 2


I use this function in python to test if a layer has a selection:

def hasSelection(lyr):
    ''' Check whether specified layer has a selection. '''
    import arcpy
    desc = arcpy.Describe(lyr)
    if len(desc.FIDSet) == 0:
        # Layer has no selection
        return False
        # Layer has a selection
        return True

You'd use an iterator if you've already got the expressions to feed in... In combination with that, you need logic Get Count, see this below - ironically in the very 1st picture it shows the very ModelBuilder logic you want to apply before a buffer execution:

Get Count (Data Management) Desktop » Geoprocessing » Tool reference » Data Management toolbox http://resources.arcgis.com/en/help/main/10.2/index.html#//0017000000n7000000

From the model perspective, this can be illustrated very simply. This is a graphic of a working model employing the Get Count precondition technique:

enter image description here

PARCELS is a parcel polygon layer in my open ArcMap document with only 2 tools employed (for simplicity), Get Count and Buffer, similar to the example from the webhelp link above. The reason I simplified the example with this model is to demonstrate the interaction more directly with the PARCELS layer which I've applied a definition query to - then I made 2 model executions, one with the def qry purposely made to return nothing (count = 0) and the other to return 1 feature (which is then essentially a pass filter to go on to the next process, Buffer).

Notice the dotted line representing the 'connector' between Row Count and Buffer - this denotes the Precondition. One way to apply this precondition is to right-click on Buffer (in this case), select properties, click on the Preconditions tab, and select Row Count (toggle checkmark) for the Precondition Variable like so:

enter image description here

(Alternately, you could use the connector tool to connect Row Count to Buffer and in the pop-up select Precondition.)

As for the 2 demos, a def query set to return None (no features) and another to return 1 feature, this is the dialog on None (a false condition):

enter image description here

...and, of course, altering the def query to return something (1 feature, in this case), this is what I call the 'pass logic', allowing Buffer to execute (a true condition):

enter image description here

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.