Select to view content in your preferred language

Model builder and exception in arcpy script

1890
1
01-20-2016 06:07 AM
by Anonymous User
Not applicable

I'm trying to finish my model... but I have a problem. I need to introduce in my model a script that choise between kriging and IDW/spline interpolation. Kriging is the default method used in my model, but If kriging return an error then I want to run IDW interpolation and pass the result to another tool.

My model runs fine with kriging interpolation, raster was produced and the tool "extract values to points" run successfully.

But if the kriging method return an error and the script calculate IDW/Spline, raster output was produced but extract values to point was unable to run successfully. And I receive this statement: "All the inputs are not current"

Immagine.pngThe error:

Parameters settings:

The script:

import arcpy

import sys

from arcpy.sa import *

limiti = arcpy.GetParameterAsText(0)

arcpy.env.mask = limiti

arcpy.env.extent = limiti

errors = 0

inFC = arcpy.GetParameterAsText(1)

campo = arcpy.GetParameterAsText(2)

outRaster = arcpy.GetParameterAsText(3)

cellSize = 1000

Modello = "Spherical"

try: 

    arcpy.Kriging_3d(inFC, campo, outRaster, Modello,cellSize, "", "") 

except Exception:

    e = sys.exc_info()[1]

    print(e.args[0])

    arcpy.AddError(e.args[0])

    errors += 1

if errors > 0:

    arcpy.Spline_3d(inFC, campo, outRaster,cellSize, "TENSION", "","")

0 Kudos
1 Reply
LukeSturtevant
Occasional Contributor III

You are going to want a 'finally' block after your 'except' block to capture the errors:

finally:
     if errors > 0:
         arcpy.Spline_3d(inFC, campo, outRaster,cellSize, "TENSION", "","")
0 Kudos