<?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: Problems with Model builder and Script PYTHON in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146443#M11437</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The following works in extreem cases where you don't want to recreate anything that is already on disk.&amp;nbsp; If you check for the existance of something then you can choose to not create it as is done below.&amp;nbsp; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#---------------------------------------------------------------------------
# delimita.py
# Created on: Thu Dec 05 2013 07:18:26 AM
# 
# Description: 
# Es importante que e Modelo de Elevacion tenga Proyeccion UTM, caso contrario, cambie al Sistema de Proyeccion Sugerido
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcpy#arcgisscripting

# Create the Geoprocessor object
#not used in 10.1
#gp = arcgisscripting.create()

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Load required toolboxes...
arcpy.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx")

# Set the Geoprocessing environment...
#not used in working example
#arcpy.extent = "DEFAULT"

#The only input variable to this script:
dem = r"C:\Users\Me\Desktop\M130_B90\M130_B90\M130_38076DSQ_BIG.dem"
# downloaded from:
# http://estuarinebathymetry.noaa.gov/bathy_htmls/M130.html


# Local variables...
lleno = r"C:\Users\Me\Desktop\M130_B90\lleno"
direccion = r"C:\Users\Me\Desktop\M130_B90\direccion"
Output_drop_raster = ""
acumula = r"C:\Users\Me\Desktop\M130_B90\acumula"
condicional = r"C:\Users\Me\Desktop\M130_B90\condicional"
Input_true_raster_or_constant_value = "1"
Expression = "Value &amp;gt; 4000"
drenaje = r"C:\Users\Me\Desktop\M130_B90\drenaje.shp"


# Process: Fill...
if not os.path.exists(lleno):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Fill_sa(dem, lleno, "")

# Process: Flow Direction...
if not os.path.exists(direccion):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FlowDirection_sa(lleno, direccion, "NORMAL", Output_drop_raster)

# Process: Flow Accumulation...
if not os.path.exists(acumula):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FlowAccumulation_sa(direccion, acumula, "", "FLOAT")

# Process: Con...
if not os.path.exists(condicional):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Con_sa(acumula, Input_true_raster_or_constant_value, condicional, "", Expression)

# Process: Stream to Feature...
if not os.path.exists(drenaje):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.StreamToFeature_sa(condicional, direccion, drenaje, "SIMPLIFY")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This same method will work for this example, but if you are looking to see if a property exists or if a file geodatabase feature class exists, you will need to use the arcpy.Exists boolean function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would consider using the script as a toolbox script tool by providing input parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for example, arcpy, or in your case:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dem = gp.GetParameterAsText(0)
output = gp.SetParemeter)(1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and then configure the parameter values using the parameters tab of the script tool properties page in arccatalog.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I realize you are using arcgis 9.x and it may not work exaclty like this but this should get you going in the right direction.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:59:38 GMT</pubDate>
    <dc:creator>MaxSquires</dc:creator>
    <dc:date>2021-12-11T07:59:38Z</dc:date>
    <item>
      <title>Problems with Model builder and Script PYTHON</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146440#M11434</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I made a Model to delimit River basins with Model Builder. When exporting in Python format and proving it in another Machine, it takes almost 40 minutes in processing and it always leaves error, not as this problem can be solved. In this file I have two models, one to calcular the direction of the flow and in the other model to delimit the River basin. The second model depends on the exits of first. There is some form to have a single model, instead of two or three. Thank you very much&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 05 Dec 2013 18:48:50 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146440#M11434</guid>
      <dc:creator>MirkoDelfin_Soruco</dc:creator>
      <dc:date>2013-12-05T18:48:50Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Model builder and Script PYTHON</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146441#M11435</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello.&amp;nbsp; I think I understand your question, but it would be helpful if you could provide your code so that we know more precisely what you mean.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy
if arcpy.Exists(output1):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.SolveNetwork(output1, output2)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;however, you may mean something more along the lines of a tool validator. These are not so easy to explain but I would go to an existing script tool (denoted by the scroll -like icon within a toolbox) and right click the tool.&amp;nbsp; in the context menu that pops up, select the Validation tab.&amp;nbsp; In here you will see the validator class that can run prerequisite components of your script tool. You can start from scratch or you can try to use the validation classes that esri has created as a starting point. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;For example, the data management toolbox contains python script tool for converting points to a line. You can view the source code for this tool but to address the issue you are having you may be interested in the validator tab which shows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import locale

class ToolValidator:
&amp;nbsp; """Class for validating a tool's parameter values and controlling
&amp;nbsp; the behavior of the tool's dialog."""

&amp;nbsp; def __init__(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Setup the Geoprocessor and the list of tool parameters."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; import arcgisscripting as ARC
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.GP = ARC.create(9.3)
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params = self.GP.getparameterinfo()

&amp;nbsp; def initializeParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Refine the properties of a tool's parameters.&amp;nbsp; This method is
&amp;nbsp;&amp;nbsp;&amp;nbsp; called when the tool is opened."""

&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].Schema.GeometryType = "Polyline"
&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].Schema.FieldsRule = "AllFIDsOnly"

&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateParameters(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the values and properties of parameters before internal
&amp;nbsp;&amp;nbsp;&amp;nbsp; validation is performed.&amp;nbsp; This method is called whenever a parmater
&amp;nbsp;&amp;nbsp;&amp;nbsp; has been changed."""

&amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[2].altered:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if self.params[0].value and self.params[2].value:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field = self.GP.CreateObject("Field")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; field.name = self.params[2].value.value
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; self.params[1].Schema.AdditionalFields = [field]
&amp;nbsp;&amp;nbsp;&amp;nbsp; return

&amp;nbsp; def updateMessages(self):
&amp;nbsp;&amp;nbsp;&amp;nbsp; """Modify the messages created by internal validation for each tool
&amp;nbsp;&amp;nbsp;&amp;nbsp; parameter.&amp;nbsp; This method is called after internal validation."""
&amp;nbsp;&amp;nbsp;&amp;nbsp; return


&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You can see from this example that if the self.params[2] parameter is modified, a function is called to add a field to the point feature.&amp;nbsp; This is where your first model could be initialized/checked for the existence of.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Good luck!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:59:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146441#M11435</guid>
      <dc:creator>MaxSquires</dc:creator>
      <dc:date>2021-12-11T07:59:36Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Model builder and Script PYTHON</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146442#M11436</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;---------------------------------------------------------------------------&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# delimita.py&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Created on: Thu Dec 05 2013 07:18:26 AM&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;#&amp;nbsp;&amp;nbsp; (generated by ArcGIS/ModelBuilder)&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Description: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;# Es importante que e Modelo de Elevacion tenga Proyeccion UTM, caso contrario, cambie al Sistema de Proyeccion Sugerido&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;# Check out any necessary licenses&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.CheckOutExtension("spatial")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Load required toolboxes...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.AddToolbox("C:/Program Files (x86)/ArcGIS/ArcToolbox/Toolboxes/Spatial Analyst Tools.tbx")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Set the Geoprocessing environment...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.extent = "DEFAULT"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Local variables...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;lleno = "C:\\cuenca\\lleno"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;direccion = "C:\\cuenca\\direccion"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Output_drop_raster = ""&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;acumula = "C:\\cuenca\\acumula"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;condicional = "C:\\cuenca\\condicional"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Input_true_raster_or_constant_value = "1"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Expression = "Value &amp;gt; 4000"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;drenaje = "C:\\cuenca\\drenaje.shp"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;dem = "C:\\cuenca\\dem"&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Fill...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Fill_sa(dem, lleno, "")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Flow Direction...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FlowDirection_sa(lleno, direccion, "NORMAL", Output_drop_raster)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Flow Accumulation...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.FlowAccumulation_sa(direccion, acumula, "", "FLOAT")&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Con...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.Con_sa(acumula, Input_true_raster_or_constant_value, condicional, "", Expression)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;# Process: Stream to Feature...&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.StreamToFeature_sa(condicional, direccion, drenaje, "SIMPLIFY")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 06 Dec 2013 09:21:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146442#M11436</guid>
      <dc:creator>MirkoDelfin_Soruco</dc:creator>
      <dc:date>2013-12-06T09:21:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problems with Model builder and Script PYTHON</title>
      <link>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146443#M11437</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;The following works in extreem cases where you don't want to recreate anything that is already on disk.&amp;nbsp; If you check for the existance of something then you can choose to not create it as is done below.&amp;nbsp; &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
#---------------------------------------------------------------------------
# delimita.py
# Created on: Thu Dec 05 2013 07:18:26 AM
# 
# Description: 
# Es importante que e Modelo de Elevacion tenga Proyeccion UTM, caso contrario, cambie al Sistema de Proyeccion Sugerido
# ---------------------------------------------------------------------------

# Import system modules
import sys, string, os, arcpy#arcgisscripting

# Create the Geoprocessor object
#not used in 10.1
#gp = arcgisscripting.create()

# Check out any necessary licenses
arcpy.CheckOutExtension("spatial")

# Load required toolboxes...
arcpy.AddToolbox(r"C:\Program Files\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Spatial Analyst Tools.tbx")

# Set the Geoprocessing environment...
#not used in working example
#arcpy.extent = "DEFAULT"

#The only input variable to this script:
dem = r"C:\Users\Me\Desktop\M130_B90\M130_B90\M130_38076DSQ_BIG.dem"
# downloaded from:
# http://estuarinebathymetry.noaa.gov/bathy_htmls/M130.html


# Local variables...
lleno = r"C:\Users\Me\Desktop\M130_B90\lleno"
direccion = r"C:\Users\Me\Desktop\M130_B90\direccion"
Output_drop_raster = ""
acumula = r"C:\Users\Me\Desktop\M130_B90\acumula"
condicional = r"C:\Users\Me\Desktop\M130_B90\condicional"
Input_true_raster_or_constant_value = "1"
Expression = "Value &amp;gt; 4000"
drenaje = r"C:\Users\Me\Desktop\M130_B90\drenaje.shp"


# Process: Fill...
if not os.path.exists(lleno):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Fill_sa(dem, lleno, "")

# Process: Flow Direction...
if not os.path.exists(direccion):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FlowDirection_sa(lleno, direccion, "NORMAL", Output_drop_raster)

# Process: Flow Accumulation...
if not os.path.exists(acumula):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.FlowAccumulation_sa(direccion, acumula, "", "FLOAT")

# Process: Con...
if not os.path.exists(condicional):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Con_sa(acumula, Input_true_raster_or_constant_value, condicional, "", Expression)

# Process: Stream to Feature...
if not os.path.exists(drenaje):
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.StreamToFeature_sa(condicional, direccion, drenaje, "SIMPLIFY")&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;This same method will work for this example, but if you are looking to see if a property exists or if a file geodatabase feature class exists, you will need to use the arcpy.Exists boolean function.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I would consider using the script as a toolbox script tool by providing input parameters.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;for example, arcpy, or in your case:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;dem = gp.GetParameterAsText(0)
output = gp.SetParemeter)(1)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;and then configure the parameter values using the parameters tab of the script tool properties page in arccatalog.&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I realize you are using arcgis 9.x and it may not work exaclty like this but this should get you going in the right direction.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:59:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/problems-with-model-builder-and-script-python/m-p/146443#M11437</guid>
      <dc:creator>MaxSquires</dc:creator>
      <dc:date>2021-12-11T07:59:38Z</dc:date>
    </item>
  </channel>
</rss>

