AnsweredAssumed Answered

Python script tool will not stop running in Model Builder

Question asked by racheski on Sep 25, 2012
Latest reply on Sep 26, 2012 by racheski
My python script tool will not stop running inside model builder.  Here is an overview of what the model does:

1. Python script called "WeightRiskLayers" creates weighted rasters based on user input and saves them into a workspace.
2. Raster iterator iterates through these weighted rasters and puts them in the Collect Values tool.
3. Cell Statistics sums the rasters together to create a "Risk Terrain."

The problem is that when I run everything outside of model builder, the python script repeats and subsequently the entire model runs again.  I even tried adding the Model Only Tool "Stop" but that did not work.

Here is the python script (sry it is long)
#Import modules import os import arcpy from arcpy import env from import * arcpy.CheckOutExtension("Spatial")  #Set local variables wks = arcpy.GetParameterAsText(0) # input workspace inRaster1 = arcpy.GetParameterAsText(1) # input raster layer inRaster2 = arcpy.GetParameterAsText(2) # input raster layer inRaster3 = arcpy.GetParameterAsText(3) # input raster layer inRaster4 = arcpy.GetParameterAsText(4) # input raster layer inRaster5 = arcpy.GetParameterAsText(5) # input raster layer inRaster6 = arcpy.GetParameterAsText(6) # input raster layer inRaster7 = arcpy.GetParameterAsText(7) # input raster layer inRaster8 = arcpy.GetParameterAsText(8) # input raster layer inRaster9 = arcpy.GetParameterAsText(9) # input raster layer inRaster10 = arcpy.GetParameterAsText(10) # input raster layer env.workspace = wks cellSize = 100 outExtent = Extent(871599.89, 982834.44, 912502.09, 1070920.9) ReMapTable_dbf = "P:\\Crime_Analysis\\Testing_Training\\RiskTerrainModeling\\RobinAdrienne\\AggAssaults\\ReMapTable.dbf"  #Multiply Raster by a constant with CreateConstantRaster constantValue1 = arcpy.GetParameterAsText(11) # input weight value outConstRaster1 = CreateConstantRaster(constantValue1, "FLOAT", cellSize, outExtent) outReclass1 = ReclassByTable(inRaster1, ReMapTable_dbf , "FROM", "TO", "VALUE") outTimes1 = outReclass1* outConstRaster1 outRaster1 = "Wt_" + os.path.basename(inRaster1) # save raster        constantValue2 = arcpy.GetParameterAsText(12) # input weight value outConstRaster2 = CreateConstantRaster(constantValue2, "FLOAT", cellSize, outExtent) outReclass2 = ReclassByTable(inRaster2, ReMapTable_dbf ,"FROM","TO","VALUE") outTimes2 = outReclass2* outConstRaster2 outRaster2 = "Wt_" + os.path.basename(inRaster2) arcpy.SetParameterAsText(13,outRaster2)  #isinstnace test for parameter input       constantValue3 = arcpy.GetParameterAsText(14) # input weight value if constantValue3:       outConstRaster3 = CreateConstantRaster(constantValue3, "FLOAT", cellSize, outExtent)       outReclass3 = ReclassByTable(inRaster3, ReMapTable_dbf ,"FROM","TO","VALUE")       outTimes3 = outReclass3* outConstRaster3       outRaster3 = "Wt_" + os.path.basename(inRaster3) else:        sys.exit()  constantValue4 = arcpy.GetParameterAsText(15) # input weight value if constantValue4:       outConstRaster4 = CreateConstantRaster(constantValue4, "FLOAT", cellSize, outExtent)       outReclass4 = ReclassByTable(inRaster4, ReMapTable_dbf ,"FROM","TO","VALUE")          outTimes4 = outReclass4* outConstRaster4       outRaster4 = "Wt_" + os.path.basename(inRaster4) else:        sys.exit()  constantValue5 = arcpy.GetParameterAsText(16) # input weight value if constantValue5:       outConstRaster5 = CreateConstantRaster(constantValue5, "FLOAT", cellSize, outExtent)       outReclass5 = ReclassByTable(inRaster5, ReMapTable_dbf ,"FROM","TO","VALUE")         outTimes5 = outReclass5* outConstRaster5       outRaster5 = "Wt_" + os.path.basename(inRaster5) else:        sys.exit()  constantValue6 = arcpy.GetParameterAsText(17) # input weight value       if constantValue6:       outConstRaster6 = CreateConstantRaster(constantValue6, "FLOAT", cellSize, outExtent)       outReclass6 = ReclassByTable(inRaster6, ReMapTable_dbf ,"FROM","TO","VALUE")       outTimes6 = outReclass6* outConstRaster6       outRaster6 = "Wt_" + os.path.basename(inRaster6) else:        sys.exit()  constantValue7 = arcpy.GetParameterAsText(18) # input weight value if constantValue7:       outConstRaster7 = CreateConstantRaster(constantValue7, "FLOAT", cellSize, outExtent)       outReclass7 = ReclassByTable(inRaster7, ReMapTable_dbf ,"FROM","TO","VALUE")       outTimes7 = outReclass7* outConstRaster7       outRaster7 = "Wt_" + os.path.basename(inRaster7) else:        sys.exit()  constantValue8 = arcpy.GetParameterAsText(19) # input weight value if constantValue8:       outConstRaster8 = CreateConstantRaster(constantValue8, "FLOAT", cellSize, outExtent)       outReclass8 = ReclassByTable(inRaster8, ReMapTable_dbf ,"FROM","TO","VALUE")        outTimes8 = outReclass8* outConstRaster8       outRaster8 = "Wt_" + os.path.basename(inRaster8) else:        sys.exit()  constantValue9 = arcpy.GetParameterAsText(20) # input weight value if constantValue9:       outConstRaster9 = CreateConstantRaster(constantValue9, "FLOAT", cellSize, outExtent)       outReclass9 = ReclassByTable(inRaster9, ReMapTable_dbf ,"FROM","TO","VALUE")       outTimes9 = outReclass9* outConstRaster9       outRaster9 = "Wt_" + os.path.basename(inRaster9)       outTimes9save(outRaster9) else:        sys.exit()  constantValue10 = arcpy.GetParameterAsText(21) # input weight value if constantValue10:       outConstRaster10 = CreateConstantRaster(constantValue10, "FLOAT", cellSize, outExtent)       outReclass10 = ReclassByTable(inRaster10, ReMapTable_dbf ,"FROM","TO","VALUE")       outTimes10 = outReclass10* outConstRaster10       outRaster10 = "Wt_" + os.path.basename(inRaster10) else:        sys.exit()       

Here is the script inside model builder:

Can I stop the model by changing the python code? Or can I do it through model builder?  Help will be met with the utmost appreciation :o