<?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 Re: making an if-then script for modelbuilder that is based on the model iteration nu in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/making-an-if-then-script-for-modelbuilder-that-is/m-p/443675#M14926</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I use &lt;/SPAN&gt;&lt;A href="http://code.google.com/p/pyscripter/" rel="nofollow noopener noreferrer" target="_blank"&gt;PyScripter&lt;/A&gt;&lt;SPAN&gt; as my Python development environment, it's very good.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OK first you need to create your script and set it up as shown below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Import system modules&lt;/SPAN&gt;
import sys, string, os, arcgisscripting

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Create the Geoprocessor object&lt;/SPAN&gt;
gp = arcgisscripting.create(9.3)

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Local variables...Try to get the iteration number that the model is on.&lt;/SPAN&gt;
IterationNum = gp.GetParameterAsText(0)

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Do stuff...&lt;/SPAN&gt;
gp.addmessage("it = " + IterationNum)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now add your script to the tool box and ensure that it has a single parameter of type text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create your model and set your model to run &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;X&lt;/SPAN&gt;&lt;SPAN&gt; times. Drag your script which is now a tool onto your model and expose the parameter and set it's value to %n%. Your script will then be able to use it but be aware that a string is passed to the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 19:50:48 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2021-12-11T19:50:48Z</dc:date>
    <item>
      <title>making an if-then script for modelbuilder that is based on the model iteration number</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/making-an-if-then-script-for-modelbuilder-that-is/m-p/443674#M14925</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to make a script that can be used to do if-then branching in model builder based on the iteration number of the underlying model.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I modeled it after the if-then script example in esri help (&lt;/SPAN&gt;&lt;A href="http://webhelp.esri.com/ARCGISDESKTOP/9.3/index.cfm?TopicName=Branching%3A_Implementing_If-Then-Else_logic&amp;amp;anchor=Adding%20the%20field%20check%20script"&gt;http://webhelp.esri.com/ARCGISDESKTOP/9.3/index.cfm?TopicName=Branching%3A_Implementing_If-Then-Else_logic&amp;amp;anchor=Adding%20the%20field%20check%20script&lt;/A&gt;&lt;SPAN&gt; )&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Here is what I came up with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I wonder if the %i% convention that modelbuilder uses to get the iteration number of the model transfers into python as a variable?&amp;nbsp; That might be my problem.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The %i% trick comes from this page: &lt;/SPAN&gt;&lt;A href="http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=822&amp;amp;pid=821&amp;amp;topicname=An_overview_of_model_iteration"&gt;http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=822&amp;amp;pid=821&amp;amp;topicname=An_overview_of_model_iteration&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;any suggestions?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# iteration-if-then1.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Created on: Thu Jan 27 2011 09:47:59 AM&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder) and then John Gallo&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# ---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Import system modules&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;import sys, string, os, arcgisscripting&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Create the Geoprocessor object&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp = arcgisscripting.create()&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables...Try to get the iteration number that the model is on.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;IterationNum = "%i%"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;#branch depending on iteration number.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;if IterationNum=1:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Addmessage("Iteration number = 1")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetParameterAsText(2, "True")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetparameterAsTExt(3, "False")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;else:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Addmessage("Iteration number NOT = 1")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetParameterAsText(2, "False")&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.SetparameterAsTExt(3, "True")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;(Oh, and to make things worse, I have tried for over an hour to install pythonwin, to no luck.&amp;nbsp; it wants a mfc71.dlll , but even when I download it, then copy it and paste it into system32 directory PyhonWin still says it needs it...)&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 27 Jan 2011 17:42:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/making-an-if-then-script-for-modelbuilder-that-is/m-p/443674#M14925</guid>
      <dc:creator>JohnGallo</dc:creator>
      <dc:date>2011-01-27T17:42:11Z</dc:date>
    </item>
    <item>
      <title>Re: making an if-then script for modelbuilder that is based on the model iteration nu</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/making-an-if-then-script-for-modelbuilder-that-is/m-p/443675#M14926</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;John,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I use &lt;/SPAN&gt;&lt;A href="http://code.google.com/p/pyscripter/" rel="nofollow noopener noreferrer" target="_blank"&gt;PyScripter&lt;/A&gt;&lt;SPAN&gt; as my Python development environment, it's very good.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;OK first you need to create your script and set it up as shown below:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Import system modules&lt;/SPAN&gt;
import sys, string, os, arcgisscripting

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Create the Geoprocessor object&lt;/SPAN&gt;
gp = arcgisscripting.create(9.3)

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Local variables...Try to get the iteration number that the model is on.&lt;/SPAN&gt;
IterationNum = gp.GetParameterAsText(0)

&lt;SPAN style="color:&amp;quot;green&amp;quot;;"&gt;# Do stuff...&lt;/SPAN&gt;
gp.addmessage("it = " + IterationNum)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Now add your script to the tool box and ensure that it has a single parameter of type text.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Create your model and set your model to run &lt;/SPAN&gt;&lt;SPAN style="font-style:italic;"&gt;X&lt;/SPAN&gt;&lt;SPAN&gt; times. Drag your script which is now a tool onto your model and expose the parameter and set it's value to %n%. Your script will then be able to use it but be aware that a string is passed to the script.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Duncan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:50:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/making-an-if-then-script-for-modelbuilder-that-is/m-p/443675#M14926</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2021-12-11T19:50:48Z</dc:date>
    </item>
  </channel>
</rss>

