I have a model which iterates through feature classes in a geodatabase. For each feature class, it runs the check Geometry tool. I then use the "Get Count" tool to count the number of rows in the output table. I then want to add an expression where if the number of rows is greater than 0 it should keep running the rest of the model, otherwise it should go on to the next feature class.

I thought this could be achieved by using the Calculate Value tool using the following code.


CountMe(%Row Count%)

Code Block

 def CountMe(n):
     import arcpy
     if n > 0:
      return "true"
      return "false"

Where %Row Count% is the output from the "Get Count" tool.

This returns True and False values, and I have the output from this set as a precondition to the next steps in the model.

However, I assumed that only "true" data would go through, but all the data seems to go through i.e. the model will push through an empty table from the Check Geometry tool all the way to the end.

I've had a read online and I think that using the Calculate Value tool is the wrong way to go about this. Am I right in assuming that what I need is a python script that will give me 2 outputs (True and False) and then I can connect the "True" as a precondition to the rest of the model, and leave the "False" disconnected, so the model stops and the iterator goes on to the next feature class?

If so, would anybody be able to give me some help with this?

Model structure

  • Programmatically speaking everything is True except 0. "False" with double quotes, is a literal string of the word "False", which is not empty and thus its true.
    – nickves
    Oct 12, 2013 at 13:26

1 Answer 1


If the precondition that checks for True or False is expecting a boolean, it will always evaulate to true because non-empty strings return true values, like so:

>>> if "true":      print "Really True!"

Really True!
>>> if "false":     print "Really True!"

Really True!

Have you tried returning True or False (booleans) instead of "true" or "false" (strings)? That might solve the issue.

def CountMe(n):         
     if n > 0:
      return True
      return False

The following is also equivalent to the above:

def CountMe(n):         
    return True if n > 0 else False

A few notes:

Importing arcpy (which seems unnecessary) can drastically slow down your code. If you have 1000 rows, you might very well be increasing run time by 15+ minutes.

enter image description here

  • Hi Paul, many thanks for your reply and the hint about importing arcpy. I was already using Boolean as the Data Type in the calculate values tool. I've tried all your suggestions above and the blank tables still go through my model (I have checked the tables and they are definitely empty). Any other suggestions? Many thanks
    – Dan_h_b
    Aug 14, 2013 at 15:39
  • @Dan_h_b, I made a model that runs Get Count and properly returns False for empty and True for non-empty. I get "The process did not execute because the precondition is false." Is Row Count set as a precondition?
    – Paul
    Aug 14, 2013 at 16:03
  • I've now attached an image to my original post showing the relevant section in my model. I'm using the output from "Calculate Value" as a precondition. I'm not using "Row Count" as a precondition. Isn't Row Count just a number? Any chance you could upload an image of your model so I can see how you've preconditioned it?
    – Dan_h_b
    Aug 14, 2013 at 18:25
  • @Dan_h_b, I added the picture of my model and the results.
    – Paul
    Aug 14, 2013 at 19:08
  • Many thanks for this. It turns out all my script logic was right and all I had to do was create a sub model. I had the Row Count as a precondition to the creation of some GDB's. I then had those GDB's as preconditions to the rest of my model, however, as the GDB's weren't being created when Row Count was 0, it meant that their precondition didn't carry forward to the rest of the model (as it didn't exist), hence the rest of the model still ran. My solution was to make the GDB creation and all subsequent tools a sub model, and had Row Count as a pre-condition to the whole sub model.
    – Dan_h_b
    Aug 15, 2013 at 15:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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