Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I have problems integrating a python script in a modelbuilder tool. I'm a absolute beginner with python. Maybe there's also an easier way to solve this problem in modelbuilder without using a python code, but I haven't found it yet

so here's my problem:

my modelbuilder tool's flow of control needs to evaluate a situation and decide on one of two courses of action: If the value in the field "Building" in my feature class is 1, it should follow one path, if the value is greater than one it should follow another path.

Here's my python code that I tried so far, but didn't work.

# Load the arcpy module
import sys, os, arcpy

# Get the input feature class from the model
InputFC = arcpy.GetParameterAsText(0)
field = "Building"
cursor = arcpy.SearchCursor(InputFC)

# check if one or more than one building footprint exist
for row in cursor:
    Building =(row.getValue(field))
    if Building == 1:
        arcpy.SetParameterAsText(1, "True")
        arcpy.SetParameterAsText(1, "False")
        arcpy.SetParameterAsText(1, "False")
        arcpy.SetParameterAsText(2, "True")

any help on this problem is much appreciated

regards nicolas

share|improve this question
Welcome to SE-GIS! If you have not seen it, a Question with similar requirements, and an alternative solution for if/then/else logic (which I like better), can be found here. –  PolyGeo Apr 29 '13 at 11:43
Something worth pointing out; as your code logic runs it will go through all the rows in your input featureclass. Does this input featureclass have only 1 row in it? If not the test of is building = 1 or not will always be dictated by the latest entry in your featureclass. –  Hornbydd Apr 29 '13 at 13:17
add comment

1 Answer

Perhaps use the Select Layer by Attribute tool in Model Builder, to select features where "Building" = 1 and "Building" > 1, run the next tools on each, and Merge back together as needed. Merge Branch may also come in handy in place of Merge.

Select Layer By Attribute, run next tool, and Merge as needed

share|improve this answer
add comment

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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