4

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
#try:
arcpy.MakeFeatureLayer_management("contoursClip", "contoursClipLayer")
**arcpy.SaveToLayerFile_management("contoursClipLayer", contoursClipLyr)**
arcpy.ApplySymbologyFromLayer_management("contoursClipLayer", contoursSymb)
#except:
 #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
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.SaveToLayerFile_management("contoursClipLayer", contoursClipLyr)**
arcpy.ApplySymbologyFromLayer_management("contoursClipLayer", contoursSymb)
#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.SaveToLayerFile_management("clipOKXLayer", clipOKXLyr)
 arcpy.ApplySymbologyFromLayer_management("clipOKXLayer", rasterSymb)
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"

parameter_properties

PolyGeo
65.5k29 gold badges115 silver badges349 bronze badges
asked Apr 6, 2012 at 23:18
3
  • Can you post a screenshot of your parameters property page? Commented Apr 7, 2012 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. Commented Apr 7, 2012 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. Commented Apr 7, 2012 at 23:25

1 Answer 1

1

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.

answered May 10, 2012 at 4:05

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.