<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic python script in modelbuilder get field value return boolean expressions in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118558#M9353</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have problems integrating a python script in a modelbuilder tool. I'm a absolute beginner with python, any help is much appreciated. Maybe there's also an easier way to solve this problem in modelbuilder, but I haven't found it yet&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so here's my problem:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my python code that I tried so far&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Building =(row.getValue(field))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Building == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "True")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(2, "True")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nicolas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Fri, 26 Apr 2013 12:59:28 GMT</pubDate>
    <dc:creator>NicolasMühlich</dc:creator>
    <dc:date>2013-04-26T12:59:28Z</dc:date>
    <item>
      <title>python script in modelbuilder get field value return boolean expressions</title>
      <link>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118558#M9353</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I have problems integrating a python script in a modelbuilder tool. I'm a absolute beginner with python, any help is much appreciated. Maybe there's also an easier way to solve this problem in modelbuilder, but I haven't found it yet&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;so here's my problem:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;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. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here's my python code that I tried so far&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;# 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Building =(row.getValue(field))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Building == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "True")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(2, "True")&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;regards&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;nicolas&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 26 Apr 2013 12:59:28 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118558#M9353</guid>
      <dc:creator>NicolasMühlich</dc:creator>
      <dc:date>2013-04-26T12:59:28Z</dc:date>
    </item>
    <item>
      <title>Re: python script in modelbuilder get field value return boolean expressions</title>
      <link>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118559#M9354</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try this:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;with arcpy.da.SearchCursor(InputFC, field) as cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in cursor:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (row[0] == 1):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I have problems integrating a python script in a modelbuilder tool. I'm a absolute beginner with python, any help is much appreciated. Maybe there's also an easier way to solve this problem in modelbuilder, but I haven't found it yet&lt;BR /&gt;&lt;BR /&gt;so here's my problem:&lt;BR /&gt;&lt;BR /&gt;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. &lt;BR /&gt;&lt;BR /&gt;Here's my python code that I tried so far&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;# 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:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Building =(row.getValue(field))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Building == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "True")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(1, "False")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SetParameterAsText(2, "True")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;regards&lt;BR /&gt;nicolas&lt;/BLOCKQUOTE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:57:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118559#M9354</guid>
      <dc:creator>CharlesShore</dc:creator>
      <dc:date>2021-12-11T06:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: python script in modelbuilder get field value return boolean expressions</title>
      <link>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118560#M9355</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Your script as it stands is only affected by the last row.&lt;/P&gt;&lt;P&gt;Here's a suggest approach: set the default (which remains if building never = 1) and only change it if you find one: &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;val1, val2 = False, True
for row in cursor:
&amp;nbsp;&amp;nbsp;&amp;nbsp; Building = row.getValue(field))
&amp;nbsp;&amp;nbsp;&amp;nbsp; if Building == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val1, val2 = True, False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break
arcpy.SetParameterAsText(1, val1)
arcpy.SetParameterAsText(2, val2)&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if there are lot of records, arcpy.da.SearchCursor (10.1 and later) maybe worth using - it may be 10-100x faster:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;val1, val2 = False, True
with arcpy.da.SearchCursor(InputFC, "Building") as rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp; for row in rows:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if row[0] == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; val1, val2 = True, False
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; break&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:57:16 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-script-in-modelbuilder-get-field-value/m-p/118560#M9355</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T06:57:16Z</dc:date>
    </item>
  </channel>
</rss>

