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 I tried to bold the line it is choking on, but it's not displaying as bold in the preview so I don't know if it will come out that way. It's the saveToLayerFile_management line in this section of code about 3/4 of the way through the entire script:

# Make feature layer for contours save it and apply symbology layer
arcpy.MakeFeatureLayer_management("contoursClip", "contoursClipLayer")
**arcpy.SaveToLayerFile_management("contoursClipLayer", contoursClipLyr)**
arcpy.ApplySymbologyFromLayer_management("contoursClipLayer", contoursSymb)

    #print "make feature layer/apply symbology for contours failed."

Can anyone enlighten me as to why it does not like this or what I am apparently missing? It is defined in the script tool as a layer file data type, with a derived/output property type/direction.

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

# Set the current workspace
env.workspace = r"C:\Project2.gdb"

#Define variables
snowAmt_In = "SnowAmt_in"
snowAmt_Cm = "SnowAmt_cm"
contourInterval = 10
numberZones = 7
OKX = r"C:\OKX.lyr"
OKXcounties = r"C:\OKXcounties.lyr"
#contoursClipLayer = r"C:\contoursClipLayer.lyr"
contoursClipLyr = r"C:\contoursClipLyr.lyr"
#clipOKXLayer = r"C:\clipOKXLayer.lyr"
clipOKXLyr = r"C:\clipOKXLyr.lyr"
contoursSymb = r"C:\contoursSymb.lyr"
rasterSymb = r"C:\rasterSymb.lyr"
contourLabelText = r"C:\contourLabelText.lyr"
mxd = r"C:\Project2.mxd"
mxd1 = arcpy.mapping.MapDocument(mxd)
mxdSave = r"C:\Projectmap.mxd"
gdb = r"C:\Project2.gdb"
df = arcpy.mapping.ListDataFrames(mxd1)[0]
contourLabel = r"C:\contourLabel.lyr"

# add field for cm

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

    print "Field already exists"

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

    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)
    snowCm = snowCmRows.next()

# Remove temp layer  

del snowCm, snowCmRows

# Interpolate point data

    # Check out the ArcGIS Spatial Analyst extension license

    # Execute Natural Neighbor
    outNatNbr = NaturalNeighbor("dec2009data", snowAmt_Cm)
    # Save the output
    print "the natural neighbor interpolation file already exists"

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

#Clip contours to OKX CWA boundary
    # Execute vector Clip tool
    arcpy.Clip_analysis("contours", OKX, "contoursClip")
    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
    print "the slice file already exists"

#Clip sliced raster data to defined boundary around OKX CWA
    # Execute raster Clip tool
    arcpy.Clip_management("dec2009Slice", "-74.79081276 40.47313532 -71.74223316 41.73718052", \
                          "clipOKX", OKX, "", "ClippingGeometry")
    print "Clip raster to OKX CWA boundary failed."

# Check in the ArcGIS Spatial Analyst extension license

#Apply symbology

# Make feature layer for contours save it and apply symbology layer
arcpy.MakeFeatureLayer_management("contoursClip", "contoursClipLayer")
**arcpy.SaveToLayerFile_management("contoursClipLayer", contoursClipLyr)**
arcpy.ApplySymbologyFromLayer_management("contoursClipLayer", contoursSymb)

    #print "make feature layer/apply symbology for contours failed."

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

# Make feature layer for raster dataset save it and apply symbology layer
    arcpy.MakeRasterLayer_management("clipOKX", "clipOKXLayer")
    arcpy.SaveToLayerFile_management("clipOKXLayer", clipOKXLyr)
    arcpy.ApplySymbologyFromLayer_management("clipOKXLayer", rasterSymb)

    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
del mxd1

print "finished"


  • Can you post a screenshot of your parameters property page? – blah238 Apr 7 '12 at 1:48
  • I think that is where my problem lies. For some reason, I thought I read/concluded from reading somewhere that output paths don't need to be included in the script tool. I can't make the property box bigger to display all of my parameters but I attached a spreadsheet with the values defined in the property box for each parameter. If you still need me to post actual screen shots, let me know. – niklas24 Apr 7 '12 at 23:21
  • oh...1 other thing. I found out that my script is slightly disjointed. I have 3 variables for the .mxd and 2 for the .gdb. I'm in the process of cleaning this up and making it more efficient...so feel free to change it if you need to. – niklas24 Apr 7 '12 at 23:25

You posted a lot of code but I could not see any use of arcpy.GetParameterAsText in it.

This is what I use to get read parameter values from the tool dialog into the Python script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.