niklas24

Script tool Value error

Discussion created by niklas24 on Apr 5, 2012
Hello. I've been struggling to get my script tool to run without receiving the following error:

<class 'arcgisscripting.ExecuteError'>: Failed to execute. Parameters are not valid.
ERROR 000735: Output Layer: Value is required
Failed to execute (SaveToLayerFile)

The script processes fine when run in PythonWin, it is only the script tool that is giving me the problem. I'm not understanding what kind of "value" it is looking for for an "Output"

The following is my script and the line it is choking on is highlighted in red. Can anyone enlighten me as to why it does not like this? It is defined in the script tool as a layer file data type, with a derived/output property type/direction. Thanks in advance:

import arcpy
from arcpy import env
from arcpy.sa import *

# Set the current workspace
env.workspace = arcpy.GetParameterAsText(0)

#Define variables
snowAmt_In = "SnowAmt_in"
snowAmt_Cm = "SnowAmt_cm"
contourInterval = arcpy.GetParameterAsText(1)
numberZones = arcpy.GetParameterAsText(2)
OKX = arcpy.GetParameterAsText(3)
OKXcounties = arcpy.GetParameterAsText(4)
contoursClipLyr = arcpy.GetParameterAsText(5)
clipOKXLyr = arcpy.GetParameterAsText(6)
contoursSymb = arcpy.GetParameterAsText(7)
rasterSymb = arcpy.GetParameterAsText(8)
contourLabelText = arcpy.GetParameterAsText(9)
mxd = arcpy.GetParameterAsText(10)
mxd1 = arcpy.mapping.MapDocument(mxd)
mxdSave = arcpy.GetParameterAsText(11)
gdb = arcpy.GetParameterAsText(12)
df = arcpy.mapping.ListDataFrames(mxd1)[0]
contourLabel = arcpy.GetParameterAsText(13)

# add field for cm

try:
    arcpy.AddField_management ("dec2009data", snowAmt_Cm, "float", "5", "2")

except:
    print "Field already exists"

# Make a feature layer for "dec2009data"
try:
    arcpy.MakeFeatureLayer_management ("dec2009data", "dec2009dataLayer")

except:
    print "File already exists"

#Create update cursor for the SnowAmt_Cm field
snowCmRows = arcpy.UpdateCursor("dec2009data")
snowCm = snowCmRows.next()

while snowCm:
    snowInch = snowCm.getValue(snowAmt_In)
    #convert inches to cm
    multiplier = 2.54
    snowInCm = snowInch * multiplier
    #print snowInCm

    # Write the snow amount (cm) to SnowAmt_Cm field 
    snowCm.setValue(snowAmt_Cm, snowInCm)
    snowCmRows.updateRow(snowCm)
    snowCm = snowCmRows.next()

# Remove temp layer 
arcpy.Delete_management("dec2009dataLayer")  

del snowCm, snowCmRows


# Interpolate point data

    # Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

try:
    # Execute Natural Neighbor
    outNatNbr = NaturalNeighbor("dec2009data", snowAmt_Cm)
    # Save the output
    outNatNbr.save("outNatNei")
except:
    print "the natural neighbor interpolation file already exists"



# Add contours to the raster
    # Execute Contour tool
try:
    Contour("outNatNei", "contours", contourInterval)
except:
    print "the contour file already exists"



#Clip contours to OKX CWA boundary
    # Execute vector Clip tool
try:
    arcpy.Clip_analysis("contours", OKX, "contoursClip")
except:
    print "clipped contours file already exists"
  

  
#Slice the raster data into a range of values of equal interval zones
    # Execute Slice tool
outSlice = Slice("outNatNei", numberZones, "EQUAL_INTERVAL")
    # Save the output
try:
    outSlice.save("dec2009Slice")
except:
    print "the slice file already exists"

#Clip sliced raster data to defined boundary around OKX CWA
    # Execute raster Clip tool
try:
    arcpy.Clip_management("dec2009Slice", "-74.79081276 40.47313532 -71.74223316 41.73718052", \
                          "clipOKX", OKX, "", "ClippingGeometry")
except:
    print "Clip raster to OKX CWA boundary failed."
 
# Check in the ArcGIS Spatial Analyst extension license
arcpy.CheckInExtension("Spatial")


#Apply symbology

# Make feature layer for contours save it and apply symbology layer
#try:
arcpy.MakeFeatureLayer_management("contoursClip", "contoursClipLayer")
arcpy.ApplySymbologyFromLayer_management("contoursClipLayer", contoursSymb)
arcpy.SaveToLayerFile_management("contoursClipLayer", contoursClipLyr)
#except:
    #print "make feature layer/apply symbology for contours failed."

# Apply label to contours
#try:
arcpy.ContourAnnotation_cartography (contoursClipLyr, gdb, "Contour", \
                                        "2000000", contourLabel)
arcpy.SaveToLayerFile_management(contourLabel, contourLabelText)
#except:
    #print "apply labels to contours failed."

# Make feature layer for raster dataset save it and apply symbology layer
try:
    arcpy.MakeRasterLayer_management("clipOKX", "clipOKXLayer")
    arcpy.ApplySymbologyFromLayer_management("clipOKXLayer", rasterSymb)
    arcpy.SaveToLayerFile_management("clipOKXLayer", clipOKXLyr)
  
except:
    print "make feature layer/apply symbology for raster failed."

#Add layers into map document
addLayer = arcpy.mapping.Layer(OKXcounties)
addLayer1 = arcpy.mapping.Layer(contourLabelText)
addLayer2 = arcpy.mapping.Layer(contoursClipLyr)
addLayer3 = arcpy.mapping.Layer(clipOKXLyr)
arcpy.mapping.AddLayer(df, addLayer, "AUTO_ARRANGE")
arcpy.mapping.AddLayer(df, addLayer1, "AUTO_ARRANGE")
arcpy.mapping.AddLayer(df, addLayer2, "AUTO_ARRANGE")
arcpy.mapping.AddLayer(df, addLayer3, "AUTO_ARRANGE")

# Add contour Labels
for lyr in arcpy.mapping.ListLayers(mxd1):
    if lyr.name == "contourLabelText":
        lyr.showLabels = True
    if lyr.name == "Contour Features":
        lyr.transparency = 100

for df in arcpy.mapping.ListDataFrames(mxd1):
    df.scale = 2000000
  
#Save to a new map document and clear variable references
mxd1.saveACopy(mxdSave)
del mxd1

print "finished"

Outcomes